%k% {opm}R Documentation

Query metadata keys

Description

Search for the presence of metadata keys, either using a vector, factor, list, formula, expression or WMD object.

Usage

  ## 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 

Arguments

x

Character vector, factor, list, formula, expression or WMD object used as query. See ‘Details’. x and table can swap their places.

table

WMD, WMDS or MOPMX object. x and table can swap their places.

Details

The behaviour of these methods depends on the object used as query. infix.largek is usually stricter than infix.k, sometimes equivalent.

See subset for usage examples with OPMS objects.

Value

Logical vector of the length of the WMD or WMDS object. For MOPMX objects, a list of such vectors.

Examples

# 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

[Package opm version 1.3.63 Index]