Skip to contents

Takes a vector of chemical names, CAS numbers, SMILES, or any identifier and returns a tibble mapping each input to its DTXSID and preferred name. Unmatched inputs are included with NA values.

Usage

dss_resolve(
  query,
  con = NULL,
  ignore_case = FALSE,
  fields = NULL,
  best_match = FALSE
)

Arguments

query

A character vector of values to resolve.

con

An optional DBI::DBIConnection.

ignore_case

If TRUE, names are matched without regard to case: preferred names, IUPAC names and synonyms. A synonym match is then always reported as "IDENTIFIER", never "ident_upper". CAS numbers, formulas, InChIKeys, SMILES and DTXSIDs are still matched exactly, because case carries meaning in a SMILES string (c and C) and in a formula (Co and CO). Default FALSE.

fields

Optional character vector naming the fields that may match: any of "PREFERRED_NAME", "CASRN", "MOLECULAR_FORMULA", "INCHIKEY", "IUPAC_NAME", "SMILES", "IDENTIFIER", "ident_upper" and "DTXSID". An input that matches only other fields is returned as unmatched. NULL (default) allows every field. Synonyms include strings that look like formulas or SMILES, so use fields, not ignore_case, to keep "CO" from matching as a formula. With ignore_case = FALSE, include "ident_upper" to keep the upper-case synonym matches; with ignore_case = TRUE it means "IDENTIFIER".

best_match

If TRUE, return one row per input and DTXSID. An input can match one substance under several fields (the synonym list repeats the preferred name, for example); only the first of these is kept, in the order "DTXSID", "PREFERRED_NAME", "CASRN", "MOLECULAR_FORMULA", "INCHIKEY", "IUPAC_NAME", "SMILES", "ident_upper", "IDENTIFIER". fields is applied first. An input that matches several substances still returns one row for each. Default FALSE.

Value

A tibble with columns: input, DTXSID, PREFERRED_NAME, CASRN, matched_on.

Details

By default every field is matched exactly and case-sensitively. The table also holds an upper-cased copy of each synonym (ident_upper), so an upper-case input can match a synonym written in another case.

Examples

if (FALSE) { # \dontrun{
dss_resolve(c("Formaldehyde", "7440-38-2", "DTXSID7020637"))

# Names and CAS numbers only, in any case
dss_resolve(
  c("formaldehyde", "CO"),
  ignore_case = TRUE,
  fields = c("PREFERRED_NAME", "IUPAC_NAME", "IDENTIFIER", "CASRN"),
  best_match = TRUE
)
} # }