Usage
check_temporal(
x,
rm = NULL,
any_missing = TRUE,
null_ok = FALSE,
.names = deparse(substitute(x))
)
test_temporal(
x,
rm = NULL,
any_missing = TRUE,
null_ok = FALSE,
.names = deparse(substitute(x))
)
assert_temporal(
x,
rm = NULL,
any_missing = TRUE,
null_ok = FALSE,
.names = deparse(substitute(x)),
.var.name = checkmate::vname(x),
add = NULL
)
expect_temporal(
x,
rm = NULL,
any_missing = TRUE,
null_ok = FALSE,
.names = deparse(substitute(x)),
info = NULL,
label = checkmate::vname(x)
)Arguments
- x
Any R object.
- rm
(Optional) A
charactervector indicating the name of classes to remove from the check. See theDetailssection for more information (Default:NULL).- any_missing
(Optional) A
logicalflag indicating if missing values are allowed (Default:TRUE).- null_ok
(Optional) A
logicalflag indicating ifNULLvalues are allowed (Default:FALSE).- .names
(Optional) A
charactervector specifying the names of the objects being tested. This argument is used internally and should not be set by the user.- .var.name
(Optional) A
characterstring indicating the name of the checked object to print in assertions. This argument is used internally and should not be set by the user.- add
(Optional) A
AssertCollectionobject indicating the collection to store assertion messages. This argument is used internally and should not be set by the user.- info
(Optional) A
characterstring with extra information to be included in the message for the `testthat“ reporter. This argument is used internally and should not be set by the user.- label
(Optional) A
characterstring indicating the name of the checked object to print in messages. This argument is used internally and should not be set by the user.
Value
test_*:TRUEif it passes the test;FALSEotherwise.check_*:TRUEif it passes the test; a string with a message otherwise.assertion_*: The same input (as invisible) if it passes the test; an error message otherwise.expect_*: The same input (as invisible) if it passes the test; an error message otherwise.
Details
These functions check the following classes of temporal objects:
classes <- c(
"Duration", "Period", "difftime", "hms", "Date", "POSIXct",
"POSIXlt", "Interval", "ts", "tsibble", "zoo", "xts", "timeDate",
"timeSeries", "circular", "yearmon", "yearqtr", "year", "quarter",
"month", "week", "day", "hour", "minute", "second", "millisecond",
"microsecond", "nanosecond"
)Examples
test_temporal(1)
#> [1] FALSE
#> [1] FALSE # Expected
test_temporal("a")
#> [1] FALSE
#> [1] FALSE # Expected
test_temporal(lubridate::dhours())
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(lubridate::hours())
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(as.difftime(1, units = "hours"))
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(hms::parse_hm("01:00"))
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(as.Date("2020-01-01"))
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(Sys.time())
#> [1] TRUE
#> [1] TRUE # Expected
int <- lubridate::interval(as.Date("2001-01-01"), as.Date("2002-01-01"))
test_temporal(int)
#> [1] TRUE
#> [1] TRUE # Expected
test_temporal(c(lubridate::dhours(), NA), any_missing = FALSE)
#> [1] FALSE
#> [1] FALSE # Expected
test_temporal(NULL, null_ok = FALSE)
#> [1] FALSE
#> [1] FALSE # Expected