Skip to contents

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.

Usage

check_timeseries(dat, par_name = "dat")

check_is_timeseries(dat)

Arguments

dat

The object to check.

par_name

The name of the parameter to display in error messages.

Value

  • check_timeseries(): Returns the original dat if it is a valid time series object. Raises an error message if dat is not a valid time series.

  • check_is_timeseries(): Logical value, TRUE if the object is a valid time series, and FALSE 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