Skip to contents

Returns a function of one argument that reports, element by element, whether each value is a valid identifier for source_db. The predicate is the shape that data-frame validation packages expect, so it drops straight into assertr::assert(), a validate::validator() rule, or a pointblank col_vals_expr() step, or into base Filter() and vapply(). It is the R counterpart of the pandera check in the Python package.

Usage

id_predicate(source_db, how = "pattern", species = NULL, version = NULL)

Arguments

source_db

Source key, for example "mondo". See sources().

how

Checking mode: "pattern" (offline, shape only), "cache" (offline existence against a snapshot), "remote" (live existence against the source API), or "existence" (cache when a snapshot is available for version, otherwise remote, or pattern for a source with no resolver).

species

Optional species context, echoed in the result. A name such as "homo_sapiens" or an NCBI taxon id such as 9606. When given, an id of a different species is invalid: Ensembl is checked from its id prefix (in pattern and remote modes), and UniProt from the entry's organism in remote mode. A species outside the source map is not checked.

version

Snapshot version. In cache mode it selects the snapshot and defaults to the latest installed one when omitted; it selects the snapshot for existence mode; ignored in pattern and remote modes.

Value

A function of one argument that returns a logical vector the same length as its input. A missing cell (NA) passes, so it is never dropped by a filter or flagged by a data-frame rule; only a malformed or non-existent id is FALSE.

Examples

is_mondo <- id_predicate("mondo")
ids <- c("MONDO:0005148", "mondo:5148", "MONDO:0018076")
is_mondo(ids)
#> [1]  TRUE FALSE  TRUE
ids[is_mondo(ids)]
#> [1] "MONDO:0005148" "MONDO:0018076"

# With assertr, if it is installed:
# library(assertr)
# df |> assert(id_predicate("mondo"), term)

# With validate, if it is installed:
# rules <- validate::validator(is_mondo := id_predicate("mondo")(term))
# validate::confront(df, rules)

# With pointblank, if it is installed:
# library(pointblank)
# create_agent(df) |>
#   col_vals_expr(~ is_valid_id(term, "mondo")) |>
#   interrogate()