variable_choices {teal.transform}R Documentation

Variable label extraction and custom selection from data

Description

[Stable]

Wrapper on choices_labeled to label variables basing on existing labels in data.

Usage

variable_choices(data, subset = NULL, fill = FALSE, key = NULL)

## S3 method for class 'character'
variable_choices(data, subset = NULL, fill = FALSE, key = NULL)

## S3 method for class 'data.frame'
variable_choices(data, subset = NULL, fill = TRUE, key = NULL)

Arguments

data

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

subset

(character or function) If character, then a vector of column names. 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.

fill

(logical(1)) if TRUE, the function will return variable names for columns with non-existent labels; otherwise will return NA for them.

key

(character) vector with names of the variables, which are part of the primary key of the data argument.

This is an optional argument, which allows to identify variables associated with the primary key and display the appropriate icon for them in the teal.widgets::optionalSelectInput() widget.

Value

Named character vector with additional attributes or delayed_data object.

Examples

library(teal.data)

ADRS <- teal.transform::rADRS
variable_choices(ADRS)
variable_choices(ADRS, subset = c("PARAM", "PARAMCD"))
variable_choices(ADRS, subset = c("", "PARAM", "PARAMCD"))
variable_choices(
  ADRS,
  subset = c("", "PARAM", "PARAMCD"),
  key = default_cdisc_join_keys["ADRS", "ADRS"]
)

# delayed version
variable_choices("ADRS", subset = c("USUBJID", "STUDYID"))

# functional subset (with delayed data) - return only factor variables
variable_choices("ADRS", subset = function(data) {
  idx <- vapply(data, is.factor, logical(1))
  names(data)[idx]
})

[Package teal.transform version 0.5.0 Index]