Description Usage Arguments Value Numeric versus double values Strict atomic values Single values Author(s) Examples
Check if an object is of a proper type, mode, length, etc. This is useful when implementing simple checks. These are used extensively in package blueprint and are all available to the users for convenience.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | is_single(x)
is_scalar_character(x, accept_na = TRUE)
is_scalar_logical(x, accept_na = TRUE)
is_scalar_integer(x, accept_na = TRUE)
is_scalar_numeric(x, accept_na = TRUE)
is_strict_atomic(x, accept_na = TRUE)
is_named_list(x, unique_names = TRUE)
is_named_vctr(x, unique_names = TRUE)
|
x |
Any R object. |
accept_na |
A scalar logical. Should |
unique_names |
A scalar logical. Should names be unique? |
All functions return a scalar logical. A TRUE
implies that the
underlying tested object is something (that something is given by
the function's name).
Numeric is either an integer or a double. Is it NOT an atomic type, it is a mode. In blueprint, modes are purposely avoided. The focus is always on types for consistency.
In package blueprint, a strict atomic value is any R value that respects the following criteria.
It is an atomic R type:
NULL
,
logical,
integer,
single,
double (or numeric),
complex,
character or
raw.
It is a pure vector that has only one non-degenerate dimension.
It does not possess any structural attributes (other than type-related attributes), not even names.
Matrices, arrays and other recursive structures are not strict atomic values. Vectors such as factors that are described by attributes (comments, levels, names, etc.) are not strict atomic values. Single values (see section Single values below) are considered to be strict atomic values.
There is no single values in R. A single
is a double that has a unique attribute called "Csingle"
set equal to TRUE
. Trying to use the old R function
is.single() will simply throw an error. This is because
so-called single values should only be used with arguments used in external
interfaces (such as .C() and .Fortran()).
Therefore, function is_single()
checks that the argument passed to it is a
double with an attribute "Csingle"
set equal to TRUE
.
Jean-Mathieu Potvin (jm@potvin.xyz)
1 2 3 | # You control whether NAs are valid.
is_scalar_character(NA_character_, accept_na = TRUE) # TRUE
is_scalar_character(NA_character_, accept_na = FALSE) # FALSE
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.