util_parse_assignments {dataquieR}R Documentation

Utility function to parse assignments

Description

This function parses labels & level assignments in the format 1 = male | 2 = female. The function also handles m = male | f = female, but this would not match the metadata concept. The split-character can be given, if not the default from SPLIT_CHAR is to be used, but this would also violate the metadata concept.

Usage

util_parse_assignments(
  text,
  split_char = SPLIT_CHAR,
  multi_variate_text = FALSE,
  split_on_any_split_char = FALSE
)

Arguments

text

Text to be parsed

split_char

Character separating assignments, may be a vector, then all will be tried and the the most likely matching one will be returned as attribute split_char of the result.

multi_variate_text

don't paste text but parse element-wise

split_on_any_split_char

split on any split split_char, if > 1 given.

Value

the parsed assignments as a named list

See Also

Other parser_functions: util_interpret_limits(), util_interpret_range(), util_parse_interval(), util_parse_redcap_rule()

Examples

## Not run: 
md <- prep_get_data_frame("meta_data")
vl <- md$VALUE_LABELS
vl[[50]] <- "low<medium < high"
a <- util_parse_assignments(vl, split_char = c(SPLIT_CHAR, "<"),
  multi_variate_text = TRUE)
b <- util_parse_assignments(vl, split_char = c(SPLIT_CHAR, "<"),
  split_on_any_split_char = TRUE, multi_variate_text = TRUE)
is_ordered <- vapply(a, attr, "split_char", FUN.VALUE = character(1)) == "<"
md$VALUE_LABELS[[50]] <- "low<medium < high"
md$VALUE_LABELS[[51]] <- "1 = low< 2=medium < 3=high"
md$VALUE_LABELS[[49]] <- "2 = medium< 1=low < 3=high" # counter intuitive
with_sl <- prep_scalelevel_from_data_and_metadata(study_data = "study_data",
  meta_data = md)
View(with_sl[, union(SCALE_LEVEL, colnames(with_sl))])

## End(Not run)


[Package dataquieR version 2.1.0 Index]