Skip to contents

This function makes it easy to use the is_scalar_* functions from {rlang} to check the type of x, and that length(x) == 1, and supports the seamless use of glue strings in the custom error message. Possible values for the type parameter are: "character", "logical", "list", "integer", "double", "string", "bool", "bytes", "raw", "vector", "complex".

Usage

check_scalar_type(x, type, message, pf = parent.frame())

Arguments

x

The object to be checked

type

A string defining the R object type that x is checked to be

message

A custom error message, as a string. Will be shown to the user if the predicate check does not succeed. Can include glued variables and {cli} semantic markup.

pf

Set as parent.frame() so variables in the caller environment can be used in the custom error message.

See also