Skip to contents

[Experimental]

*_hms() check if an argument is a hms object.

Usage

check_hms(
  x,
  lower = -Inf,
  upper = Inf,
  any_missing = TRUE,
  null_ok = FALSE,
  .names = deparse(substitute(x))
)

test_hms(
  x,
  lower = -Inf,
  upper = Inf,
  any_missing = TRUE,
  null_ok = FALSE,
  .names = deparse(substitute(x))
)

assert_hms(
  x,
  lower = -Inf,
  upper = Inf,
  any_missing = TRUE,
  null_ok = FALSE,
  .names = deparse(substitute(x)),
  .var.name = checkmate::vname(x),
  add = NULL
)

expect_hms(
  x,
  lower = -Inf,
  upper = Inf,
  any_missing = TRUE,
  null_ok = FALSE,
  .names = deparse(substitute(x)),
  info = NULL,
  label = checkmate::vname(x)
)

Arguments

x

Any R object.

lower

(Optional) A value of the same class as x indicating the minimum value of x (Default: -Inf).

upper

(Optional) A value of the same class as x indicating the maximum value of x (Default: Inf).

any_missing

(Optional) A logical flag indicating if missing values are allowed (Default: TRUE).

null_ok

(Optional) A logical flag indicating if NULL values are allowed (Default: FALSE).

.names

(Optional) A character vector 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 character string 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 AssertCollection object indicating the collection to store assertion messages. This argument is used internally and should not be set by the user.

info

(Optional) A character string 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 character string 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_*: TRUE if it passes the test; FALSE otherwise.

  • check_*: TRUE if 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.

Examples

test_hms(1)
#> [1] FALSE
#> [1] FALSE # Expected

test_hms(lubridate::dhours(1))
#> [1] FALSE
#> [1] FALSE # Expected

test_hms(hms::parse_hm("01:00"))
#> [1] TRUE
#> [1] TRUE # Expected

test_hms(hms::parse_hm("01:00"), lower = hms::parse_hm("02:00"))
#> [1] FALSE
#> [1] FALSE # Expected

test_hms(hms::parse_hm("02:00"), upper = hms::parse_hm("01:00"))
#> [1] FALSE
#> [1] FALSE # Expected

test_hms(c(hms::parse_hm("01:00"), NA), any_missing = FALSE)
#> [1] FALSE
#> [1] FALSE # Expected

test_hms(NULL, null_ok = FALSE)
#> [1] FALSE
#> [1] FALSE # Expected