无法删除 R 中某些库的警告和消息
Unable to remove warnings and messages for some library in R
我无法理解这些消息来自哪个库:
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
我已经使用以下方法抑制了代码中使用的所有库的警告和消息:
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)))
我试过抑制 lubridate 和 zoo。仍然没有变化。
请建议我应该如何抑制上述消息。
数据框是这样的:
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
代码:
# 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
它似乎不是来自任何包,而是您的 if 语句条件的逻辑。 R 试图告诉您 tclass 不是您可能怀疑或可能不怀疑的原子值,而是 list/vector 值。因此,与其查看此 vector/list 中的所有值以放入 if 条件,它只会考虑此 vector/list.
的第一个元素
解决方案:确保 tclass 是一个原子值以消除警告,如果你知道它是一个向量并且你不介意它是否使用第一个值那么你就很好。
加上一起删除警告消息,请使用 options(warn=-1)
我无法理解这些消息来自哪个库:
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
我已经使用以下方法抑制了代码中使用的所有库的警告和消息:
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)))
我试过抑制 lubridate 和 zoo。仍然没有变化。
请建议我应该如何抑制上述消息。
数据框是这样的:
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
代码:
# 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
它似乎不是来自任何包,而是您的 if 语句条件的逻辑。 R 试图告诉您 tclass 不是您可能怀疑或可能不怀疑的原子值,而是 list/vector 值。因此,与其查看此 vector/list 中的所有值以放入 if 条件,它只会考虑此 vector/list.
的第一个元素解决方案:确保 tclass 是一个原子值以消除警告,如果你知道它是一个向量并且你不介意它是否使用第一个值那么你就很好。
加上一起删除警告消息,请使用 options(warn=-1)