ct_map: Recode according to controlled terminology

View source: R/ct.R

ct_mapR Documentation

Recode according to controlled terminology

Description

ct_map() recodes a vector following a controlled terminology.

Usage

ct_map(
  x,
  ct_spec = NULL,
  ct_clst = NULL,
  from = ct_spec_vars("from"),
  to = ct_spec_vars("to")
)

Arguments

x

A character vector of terms to be recoded following a controlled terminology.

ct_spec

A tibble providing a controlled terminology specification.

ct_clst

A character vector indicating a set of possible controlled terminology codelists codes to be used for recoding. By default (NULL) all codelists available in ct_spec are used.

from

A character vector of column names indicating the variables containing values to be matched against for terminology recoding.

to

A single string indicating the column whose values are to be recoded into.

Value

A character vector of terminology recoded values from x. If no match is found in the controlled terminology spec provided in ct_spec, then x values are returned in uppercase. If ct_spec is not provided x is returned unchanged.

Examples

# A few example terms.
terms <-
  c(
    "/day",
    "Yes",
    "Unknown",
    "Prior",
    "Every 2 hours",
    "Percentage",
    "International Unit"
  )

# Load a controlled terminology example
(ct_spec <- read_ct_spec_example("ct-01-cm"))

# Use all possible matching terms in the controlled terminology.
ct_map(x = terms, ct_spec = ct_spec)

# Note that if the controlled terminology mapping is restricted to a codelist
# code, e.g. C71113, then only `"/day"` and `"Every 2 hours"` get mapped to
# `"QD"` and `"Q2H"`, respectively; remaining terms won't match given the
# codelist code restriction, and will be mapped to an uppercase version of
# the original terms.
ct_map(x = terms, ct_spec = ct_spec, ct_clst = "C71113")


sdtm.oak documentation built on April 3, 2025, 9:37 p.m.