Unable to remove warnings and messages for some library in R

点点圈 提交于 2019-12-25 10:19:08

问题


I could not understand from which library these messages are coming from:

Warning messages:
1: In if (!(tclass %in% c("yearmon", "yearqtr"))) lubridate::tz(ret) <- tzone :
  the condition has length > 1 and only the first element will be used
2: In if (!(tclass %in% c("yearmon", "yearqtr"))) lubridate::tz(ret) <- tzone :
  the condition has length > 1 and only the first element will be used

I have already suppressed warnings and messages of all the libraries used in my code using:

suppressWarnings(suppressMessages(library(methods)))
suppressWarnings(suppressMessages(library(jsonlite)))
suppressWarnings(suppressMessages(library(tseries)))
suppressWarnings(suppressMessages(library(forecast)))
suppressWarnings(suppressMessages(library(sweep)))      # Broom tidiers for forecast pkg
suppressWarnings(suppressMessages(library(timekit)))    # Working with time series in R
suppressWarnings(suppressMessages(library(tidyquant)))  # Get's data from FRED, loads tidyverse behind the scenes
suppressWarnings(suppressMessages(library(data.table)))
suppressWarnings(suppressMessages(library(stringr)))
suppressWarnings(suppressMessages(library(httr)))

I've tried suppressing for lubridate and zoo. Still no change.

Please suggest what should I do to suppress above mentioned messages.

Dataframe is like this :

1499889600, 18.71832

1499893200, 19.02870

1499896800, 18.91708

1499900400, 18.80855

1499904000, 19.04631

1499907600, 18.89747

1499911200, 18.69003

1499914800, 18.98538

1499918400, 18.87732

1499922000, 18.69314

1499925600, 18.99397

1499929200, 18.77869

1499932800, 18.68454

1499936400, 18.98039

1499940000, 18.88998

1499943600, 18.71440

1499947200, 18.98789

1499950800, 18.86854

1499954400, 18.69711

1499958000, 18.91687

1499961600, 18.89083

1499965200, 18.82566

1499968800, 19.00667

1499972400, 18.87633

1499976000, 18.72960

1499979600, 19.04492

1499983200, 18.91356

1499986800, 18.83017

1499990400, 19.02865

1499994000, 18.88282

1499997600, 18.70087

1500001200, 19.06607

1500004800, 18.80885

1500008400, 18.61242

1500012000, 18.94070

1500015600, 18.82240

1500019200, 18.68274

1500022800, 18.97367

1500026400, 18.79754

1500030000, 18.72475

1500033600, 18.94517

1500037200, 18.93362

1500040800, 18.69782

1500044400, 19.02091

1500048000, 18.83109

1500051600, 18.74415

1500055200, 18.89581

1500058800, 18.90286

Code :

# Use as_datetime to convert from numeric time stamps to date-times

    dataframe <- dataframe %>%
        mutate(timestamp = as_datetime(timestamp))

# Setup your ts object

    ts_frequency <- 24
    start <- 1
    tk_ts_dataframe <- tk_ts(dataframe, start = start, freq = ts_frequency, silent = TRUE)

    # Arima model
    fit <- auto.arima(tk_ts_dataframe, trace = TRUE, stepwise = FALSE) 

    # Forecast
    forecast_duration <- 10
    fc <- forecast(fit, h = forecast_duration)

    # Perform sweep
    final <- sw_sweep(fc, timekit_idx = TRUE)
    final

回答1:


It does not appear to be coming from any package but instead the logic of your if statement condition. R is trying to tell you that tclass is not an atomic value as you may or may not have suspected but instead a list/vector of values. So instead of looking at all the values in this vector/list to put into the if condition, it will only consider the first element of this vector/list.

Solution: Make sure tclass is an atomic value to get rid of the warning, if you know that it is a vector and you don't mind if it uses the first value then you're good.

Plus to get rid of warning messages all together use options(warn=-1)



来源:https://stackoverflow.com/questions/45178635/unable-to-remove-warnings-and-messages-for-some-library-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!