Check scalar date
check_scalar_date.RdCheck if arg is a scalar date vector.
Arguments
- arg
(object)
The argument to check.- signal
(string:
c("error", "warning", "message"))
Must be one of"error","warning", or"message"."error"(default) callsbase::stop()to signal an error message."warning"callsbase::warning()to signal a warning message."message"callsbase::message()to signal a message.- msg
(string or
NULL:NULL)
A string that replaces the default message. Set asNULLto use the default message.- call.
(Scalar logical:
c(FALSE, TRUE))
Passed tostop()orwarning(). The defaultmsgincludes it's own formatted call, hencecall.should beFALSE(default). If you insert your ownmsg, then you may wantcall. = TRUE.
See also
Other check_type:
check_atomic(),
check_character(),
check_data_frame(),
check_data_frame_or_matrix(),
check_date(),
check_date_or_datetime(),
check_datetime(),
check_double(),
check_factor(),
check_flag(),
check_formula(),
check_function(),
check_function_or_numeric(),
check_inherits(),
check_integer(),
check_list(),
check_logical(),
check_matrix(),
check_named(),
check_nonempty_string(),
check_nonmissing(),
check_numeric(),
check_numeric_or_logical(),
check_probability(),
check_real(),
check_scalar_character(),
check_scalar_datetime(),
check_scalar_double(),
check_scalar_factor(),
check_scalar_integer(),
check_scalar_logical(),
check_scalar_numeric(),
check_scalar_probability(),
check_scalar_whole_number(),
check_scalar_whole_numeric(),
check_string(),
check_table(),
check_valid(),
check_valid_numeric(),
check_whole_number(),
check_whole_numeric()
Examples
#----------------------------------------------------------------------------
# check_scalar_date() examples
#----------------------------------------------------------------------------
library(bkcheck)
f <- function(x) {
x |>
check_scalar_date()
}
f(Sys.Date())
try(f(c(Sys.Date(), Sys.Date() - 1)))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = '2026-06-14', '2026-06-13'
#> class(x) = 'Date'
#> length(x) = 2
#>
#> Call: f(x = c(Sys.Date(), Sys.Date() - 1))
try(f(TRUE))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = TRUE
#> class(x) = 'logical'
#> length(x) = 1
#>
#> Call: f(x = TRUE)
try(f(Sys.time()))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = '2026-06-14 20:23:13.804148'
#> class(x) = 'POSIXct', 'POSIXt'
#> length(x) = 1
#>
#> Call: f(x = Sys.time())
try(f(1L))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = 1
#> class(x) = 'integer'
#> length(x) = 1
#>
#> Call: f(x = 1L)
try(f(1))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = 1
#> class(x) = 'numeric'
#> length(x) = 1
#>
#> Call: f(x = 1)
try(f(factor("a")))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = 'a'
#> class(x) = 'factor'
#> length(x) = 1
#>
#> Call: f(x = factor("a"))
try(f("a"))
#> Error : Argument `x` must be a scalar date vector.
#>
#> `x` = 'a'
#> class(x) = 'character'
#> length(x) = 1
#>
#> Call: f(x = "a")