%k% {opm} | R Documentation |
Search for the presence of metadata keys, either using a
vector, factor, list, formula, expression or
WMD
object.
## S4 method for signature 'ANY,MOPMX' x %K% table ## S4 method for signature 'MOPMX,ANY' x %K% table ## S4 method for signature 'MOPMX,MOPMX' x %K% table ## S4 method for signature 'MOPMX,WMD' x %K% table ## S4 method for signature 'MOPMX,WMDS' x %K% table ## S4 method for signature 'WMD,ANY' x %K% table ## S4 method for signature 'WMD,MOPMX' x %K% table ## S4 method for signature 'WMD,WMD' x %K% table ## S4 method for signature 'WMD,WMDS' x %K% table ## S4 method for signature 'WMDS,ANY' x %K% table ## S4 method for signature 'WMDS,MOPMX' x %K% table ## S4 method for signature 'character,WMD' x %K% table ## S4 method for signature 'character,WMDS' x %K% table ## S4 method for signature 'expression,WMD' x %K% table ## S4 method for signature 'expression,WMDS' x %K% table ## S4 method for signature 'factor,WMD' x %K% table ## S4 method for signature 'factor,WMDS' x %K% table ## S4 method for signature 'formula,WMD' x %K% table ## S4 method for signature 'formula,WMDS' x %K% table ## S4 method for signature 'list,WMD' x %K% table ## S4 method for signature 'list,WMDS' x %K% table ## S4 method for signature 'ANY,MOPMX' x %k% table ## S4 method for signature 'MOPMX,ANY' x %k% table ## S4 method for signature 'MOPMX,MOPMX' x %k% table ## S4 method for signature 'MOPMX,WMD' x %k% table ## S4 method for signature 'MOPMX,WMDS' x %k% table ## S4 method for signature 'WMD,ANY' x %k% table ## S4 method for signature 'WMD,MOPMX' x %k% table ## S4 method for signature 'WMD,WMD' x %k% table ## S4 method for signature 'WMD,WMDS' x %k% table ## S4 method for signature 'WMDS,ANY' x %k% table ## S4 method for signature 'WMDS,MOPMX' x %k% table ## S4 method for signature 'character,WMD' x %k% table ## S4 method for signature 'character,WMDS' x %k% table ## S4 method for signature 'expression,WMD' x %k% table ## S4 method for signature 'expression,WMDS' x %k% table ## S4 method for signature 'factor,WMD' x %k% table ## S4 method for signature 'factor,WMDS' x %k% table ## S4 method for signature 'formula,WMD' x %k% table ## S4 method for signature 'formula,WMDS' x %k% table ## S4 method for signature 'list,WMD' x %k% table ## S4 method for signature 'list,WMDS' x %k% table
x |
Character vector, factor, list, formula,
expression or |
table |
|
The behaviour of these methods depends on the object used
as query. infix.largek
is usually stricter than
infix.k
, sometimes equivalent.
Using a character vector as query, infix.k
tests
whether all given keys are present in the top-level names
of the metadata (these may be nested, but all contained
lists are ignored here). An empty query vector results in
TRUE
. Note that the values of the character
vector, not its names, if any, are used for querying the
metadata. In contrast, infix.largek
tests whether
a given key is present in the metadata and fetches an
object that is not NULL
. If the key has a length >
1, contained lists are queried.
Using a list as query, both methods tests whether
all given keys are present in the names of the metadata.
This works like the character method, but because a query
list is given, the comparison of keys can be applied
recursively (by using, of course, a nested query list).
This is based on contains
with the
values
argument set to FALSE
.
When supplying a WMD
object as query,
its metadata will be used in a list query.
The factor method first converts x
to
‘character’ mode.
The formula method attempts to evaluate the right
side of the formula in the context of the metadata of
table
and returns whether or not this fails
(yields an error). Symbols that are not found within the
metadata are looked up in the enclosing environment
infix.k
or only in the base environment
infix.largek
. But note also that missing objects
are not the only potential reason of failure.
The expression method works like the formula method, using the entire expression in place of the right side of the formula.
See subset
for usage
examples with OPMS
objects.
Logical vector of the length of the WMD
or
WMDS
object. For MOPMX
objects, a list of such vectors.
# The data set contains the metadata keys 'Species' and 'Experiment' but
# neither 'Trial' nor 'Organism' nor 'Run':
# In the following we use stopifnot(), which fails unless all arguments
# passed are TRUE.
## Character methods
# Zero-element queries
stopifnot(character() %k% vaas_1) # always results
stopifnot(character() %K% vaas_1)
# Single-element queries
stopifnot("Experiment" %k% vaas_1) # present
stopifnot("Experiment" %K% vaas_1) # present
stopifnot("Species" %k% vaas_1) # present
stopifnot("Species" %K% vaas_1) # present
stopifnot(!"Run" %k% vaas_1) # missing
stopifnot(!"Run" %K% vaas_1) # missing
stopifnot(!"Organism" %k% vaas_1) # missing
stopifnot(!"Trial" %K% vaas_1) # missing
# Multi-element queries
stopifnot(!c("Species", "Trial") %k% vaas_1) # only one present
stopifnot(!c("Organism", "Experiment") %k% vaas_1) # only one present
stopifnot(c("Species", "Experiment") %k% vaas_1) # all present
# querying with %K% and vectors of length > 1 mean nested queries; compare
# this to the behaviour of %k%!
stopifnot(!c("Species", "Experiment") %K% vaas_1)
# i.e. "Experiment" is not within "Species".
## List methods
stopifnot(list(Experiment = "whatever") %k% vaas_1) # key present
stopifnot(list(Species = "ignored") %k% vaas_1) # key present
stopifnot(vaas_1 %k% vaas_1) # obviously
stopifnot(vaas_1 %K% vaas_1)
# This fails because we query with a named 2nd-order list but the 'Species'
# metadata entry is not even a list.
stopifnot(!list(Species = list(Genus = "X", Epithet = "Y")) %k% vaas_1)
# This is OK because we query with an unnamed 2nd-order list: it has no
# names that one would fail to find.
stopifnot(list(Species = list("X", "Y")) %k% vaas_1)
# More non-nested query examples
stopifnot(!list(Run = 99) %k% vaas_1) # key not present
stopifnot(list(Species = "?", Experiment = NA) %k% vaas_1) # keys present
stopifnot(!list(Species = "?", Trial = NA) %k% vaas_1) # one key missing
stopifnot(!list(Organism = "?", Experiment = NA) %k% vaas_1) # likewise
stopifnot(list() %k% vaas_1) # empty query always results
# Formulae for querying, compare with list examples above
stopifnot((~ Experiment) %k% vaas_1) # key present
stopifnot((~ Experiment) %K% vaas_1)
stopifnot(vaas_1 %k% ~ Experiment) # key present, no parens needed
stopifnot(vaas_1 %K% ~ Experiment)
stopifnot(vaas_1 %k% ~ Species) # key present, no parens needed
stopifnot(vaas_1 %K% ~ Species)
stopifnot(!vaas_1 %k% ~ Species$Epithet) # nested key not present
stopifnot(!vaas_1 %K% ~ Species$Epithet)
stopifnot(!vaas_1 %k% ~ missing.name) # key not present
stopifnot(!vaas_1 %K% ~ missing.name)
missing.name <- "abc"
stopifnot(vaas_1 %k% ~ missing.name) # key found in enclosing environment
stopifnot(!vaas_1 %K% ~ missing.name) # enclosing environment ignored
rm(missing.name) # tidy up