value_choices {teal.transform}R Documentation

Value labeling and filtering based on variable relationship

Description

[Stable]

Wrapper on choices_labeled to label variable values basing on other variable values.

Usage

value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

## S3 method for class 'character'
value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

## S3 method for class 'data.frame'
value_choices(data, var_choices, var_label = NULL, subset = NULL, sep = " - ")

Arguments

data

(data.frame, character) If data.frame, then data to extract labels from. If character, then name of the dataset to extract data from once available.

var_choices

(character or NULL) vector with choices column names.

var_label

(character) vector with labels column names.

subset

(character or function) If character, vector with values to subset. If function, then this function is used to determine the possible columns (e.g. all factor columns). In this case, the function must take only single argument "data" and return a character vector.

See examples for more details.

sep

(character) separator used in case of multiple column names.

Value

named character vector or delayed_data object.

Examples

ADRS <- teal.transform::rADRS
value_choices(ADRS, "PARAMCD", "PARAM", subset = c("BESRSPI", "INVET"))
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"))
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"),
  subset = c("BESRSPI - ARM A", "INVET - ARM A", "OVRINV - ARM A")
)
value_choices(ADRS, c("PARAMCD", "ARMCD"), c("PARAM", "ARM"), sep = " --- ")

# delayed version
value_choices("ADRS", c("PARAMCD", "ARMCD"), c("PARAM", "ARM"))

# functional subset
value_choices(ADRS, "PARAMCD", "PARAM", subset = function(data) {
  levels(data$PARAMCD)[1:2]
})

[Package teal.transform version 0.5.0 Index]