The function creates the variables specified by the set_values_to argument,
catches errors, provides user friendly error messages, and optionally checks
the type of the created variables.
process_set_values_to(dataset, set_values_to = NULL, expected_types = NULL)Input dataset
none
Variables to set
A named list returned by exprs() defining the variables to be set, e.g.
exprs(PARAMCD = "OS", PARAM = "Overall Survival") is expected. The values
must be symbols, character strings, numeric values, expressions, or NA.
NULL
If the argument is specified, the specified variables are checked whether
the specified type matches the type of the variables created by
set_values_to.
A character vector with values "numeric" or "character"
NULL
The input dataset with the variables specified by set_values_to
added/updated
library(dplyr)
data <- tribble(
~AVAL,
20
)
try(
process_set_values_to(
data,
set_values_to = exprs(
PARAMCD = BMI
)
)
)
#> Error in process_set_values_to(data, set_values_to = exprs(PARAMCD = BMI)) :
#> Assigning variables failed!
#> • `set_values_to = exprs(PARAMCD = BMI)`
#> See error message below:
#> ℹ In argument: `PARAMCD = BMI`. Caused by error: ! object 'BMI' not found
try(
process_set_values_to(
data,
set_values_to = exprs(
PARAMCD = 42
),
expected_types = c(PARAMCD = "character")
)
)
#> Error in process_set_values_to(data, set_values_to = exprs(PARAMCD = 42), :
#> The following variables have an unexpected type:
#> • PARAMCD: expected is <character>, but it is <numeric>.