check_timeseries()
and check_is_timeseries()
are functions
that check if an input is a valid time series object of class ts
or
xts
. The check_timeseries()
function raises an error if the
input is not a time series object, while check_is_timeseries()
returns TRUE
if the input is a valid time series and FALSE
otherwise.
Value
check_timeseries()
: Returns the originaldat
if it is a valid time series object. Raises an error message ifdat
is not a valid time series.check_is_timeseries()
: Logical value,TRUE
if the object is a valid time series, andFALSE
otherwise.
Examples
# Examples for check_timeseries()
# -------------------------------
dat <- ts(c(1, 2, 3, 4, 5))
print(dat)
#> Time Series:
#> Start = 1
#> End = 5
#> Frequency = 1
#> [1] 1 2 3 4 5
check_timeseries(dat)
#> Time Series:
#> Start = 1
#> End = 5
#> Frequency = 1
#> [1] 1 2 3 4 5
df <- data.frame(x = 1:5)
try(check_timeseries(df))
#> Error in check_timeseries(df) :
#> Expected a time series object of class 'ts' or 'xts' but got data.frame
# Examples for check_is_timeseries()
# ----------------------------------
check_is_timeseries(dat)
#> [1] TRUE
check_is_timeseries(df)
#> [1] FALSE