process_selectors {cards} | R Documentation |
Process tidyselectors
Description
Functions process tidyselect arguments passed to functions in the cards package. The processed values are saved to the calling environment, by default.
-
process_selectors()
: the arguments will be processed with tidyselect and converted to a vector of character column names. -
process_formula_selectors()
: for arguments that expect named lists or lists of formulas (where the LHS of the formula is a tidyselector). This function processes these inputs and returns a named list. If a name is repeated, the last entry is kept. -
fill_formula_selectors()
: when users override the default argument values, it can be important to ensure that each column from a data frame is assigned a value. This function checks that each column indata
has an assigned value, and if not, fills the value in with the default value passed here. -
compute_formula_selector()
: used inprocess_formula_selectors()
to evaluate a single argument. -
check_list_elements()
: used to check the class/type/values of the list elements, primarily those processed withprocess_formula_selectors()
. -
cards_select()
: wrapstidyselect::eval_select() |> names()
, and returns better contextual messaging when errors occur.
Usage
process_selectors(data, ...)
process_formula_selectors(data, ...)
fill_formula_selectors(data, ...)
## S3 method for class 'data.frame'
process_selectors(data, ..., env = caller_env())
## S3 method for class 'data.frame'
process_formula_selectors(
data,
...,
env = caller_env(),
include_env = FALSE,
allow_empty = TRUE
)
## S3 method for class 'data.frame'
fill_formula_selectors(data, ..., env = caller_env())
compute_formula_selector(
data,
x,
arg_name = caller_arg(x),
env = caller_env(),
strict = TRUE,
include_env = FALSE,
allow_empty = TRUE
)
check_list_elements(
x,
predicate,
error_msg = NULL,
arg_name = rlang::caller_arg(x)
)
cards_select(expr, data, ..., arg_name = NULL)
Arguments
data |
( |
... |
(
|
env |
( |
include_env |
( |
allow_empty |
( |
x |
|
arg_name |
( |
strict |
( |
predicate |
( |
error_msg |
( |
expr |
( |
Value
process_selectors()
, fill_formula_selectors()
, process_formula_selectors()
and check_list_elements()
return NULL. compute_formula_selector()
returns a
named list.
Examples
example_env <- rlang::new_environment()
process_selectors(ADSL, variables = starts_with("TRT"), env = example_env)
get(x = "variables", envir = example_env)
fill_formula_selectors(ADSL, env = example_env)
process_formula_selectors(
ADSL,
statistic = list(starts_with("TRT") ~ mean, TRTSDT = min),
env = example_env
)
get(x = "statistic", envir = example_env)
check_list_elements(
get(x = "statistic", envir = example_env),
predicate = function(x) !is.null(x),
error_msg = c(
"Error in the argument {.arg {arg_name}} for variable {.val {variable}}.",
"i" = "Value must be a named list of functions."
)
)
# process one list
compute_formula_selector(ADSL, x = starts_with("U") ~ 1L)