Description Usage Arguments Details Value See Also Examples
One use of contains
is to test whether all names
of a query list occur as names in a data list and
optionally also whether they point to the same elements;
this principle is applied recursively to all contained
lists. The check
methods apply various tests to
objects.
1 2 3 4 5 6 7 |
object |
List or data frame containing the data, or character vector describing problems, if any. |
against |
Character vector whose names indicate
column names of |
other |
List used as query. |
values |
Logical scalar. Compare also the values or
only the keys? If |
exact |
Logical scalar. If If |
... |
Optional arguments passed to |
Non-list elements are ignored by contains
if
values
is FALSE
. Otherwise the comparison
is done using identical
if exact
is
TRUE
. If exact
is FALSE
, the
value(s) in the data list can be any of the values at the
corresponding position in the query list, and the
comparison is done by coercion to character vectors. An
empty query list results in TRUE
. Missing names in
a non-empty query list result in FALSE
.
The check
method for data frames tests for the
presence of each column listed by against
in
object
. For the columns found, it checks whether
is.<name>
returns TRUE
, which <name>
given by the according element of against
. It is
an error if the function is.<name>
does not exist.
The check
method for character vectors is a simple
helper method that raises an error unless the vector is
empty.
contains
yields a logical scalar, check
a
(potentially empty) character vector describing each
failed assertion when object
is a list.
base::list base::as.list base::'[' base::'[[' base::match
base::identity
Other coding-functions: L
,
LL
, assert
,
case
, collect
, flatten
,
listing
, map_names
,
map_values
, must
,
set
, sql
,
unnest
1 2 3 4 5 6 7 8 9 10 11 12 13 | # contains() list/list method
x <- list(a = 1:8, c = 9, d = list(d1 = 'x', d2 = 'y'))
y <- list(a = 1:10, c = "9", d = list(d1 = "x"))
stopifnot(contains(x, y))
stopifnot(!contains(x, y, exact = TRUE))
stopifnot(contains(x, y, exact = TRUE, values = FALSE))
# check() data.frame/character method
(x <- check(Puromycin,
c(conc = "numeric", rate = "numeric", state = "factor")))
(y <- check(Puromycin,
c(missing = "numeric", rate = "numeric", state = "character")))
stopifnot(is.character(x), is.character(y))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.