Learn R Programming

favr (version 2.0.0)

modifiers: Modify the behaviour of type checking functions

Description

Modify the type-checking, or length-checking behaviour of favr type checking functions.

Usage

bare(x, arg = caller_arg(x))

at_least(n, arg = caller_arg(n))

at_most(n, arg = caller_arg(n))

in_range( n_min, n_max, arg_min = caller_arg(n_min), arg_max = caller_arg(n_max) )

Value

A list of class favr_modifier with named elements obj, bare

and arg for bare(), and at_least and/or at_most for the length modifiers.

Arguments

x

An object to modify the check behaviour for.

arg, arg_min, arg_max

An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.

n, n_min, n_max

Single numeric value that is castable to an integer. Must be zero or positive.

Details

Use bare() to check if a given object is a bare R object (no class attribute, see is.object()), throwing an error if it is not and passing the object on to the check if it is.

For S3 type checks, bare() checks that the object has the expected S3 type as the first element of the class vector.

To modify the behaviour of length checking arguments n, nrow, and ncol (example described for n):

  • at_least(n) means the object must be at least length (>=) n.

  • at_most(n) means the object must be at most length (<=) n.

  • in_range(n_min, n_max) means the object length must be within the range of (>=) n_min and (<=) n_max.

See Also

type-checks, scalar-type-checks, s3-type-checks, property-checks and s3-check-builders for the functions that these modifiers can be used with.

Examples

Run this code
bare(1)
at_least(1)
at_most(1)
in_range(1, 2)

at_least(1.5) |> try()

check_integer(bare(factor(1))) |> try()
check_integer(1:5, n = at_least(10)) |> try()
check_integer(1:5, n = at_most(3)) |> try()
check_integer(1:5, n = in_range(2, 4)) |> try()

x <- as.Date("2000-01-01")
class(x) <- c("my_date", class(x))
check_date(bare(x)) |> try()

Run the code above in your browser using DataLab