manage_key_colnames {scrutiny} | R Documentation |
Enable name-independent key column identification
Description
A handwritten mapper function for consistency tests, such as
grim_map()
, may include arguments named after the key columns in its
input data frame. When such an argument is specified by the user as a
column name of the input data frame, it identifies a differently-named
column as that key column.
Create such functionality in three steps:
Add arguments to your mapper function named after the respective key columns. They should be
NULL
by default; e.g.,x = NULL, n = NULL
.Within the mapper, capture the user input by quoting it using
rlang::enexpr()
. Reassign these values to the argument variables; e.g.,x <- rlang::enexpr(x)
andn <- rlang::enexpr(n)
.For every such argument, call
manage_key_colnames()
and reassign its value to the input data frame variable, adding a short description; e.g.,data <- manage_key_colnames(data, x, "mean/proportion")
anddata <- manage_key_colnames(data, n, "sample size")
.
Usage
manage_key_colnames(data, arg, description = NULL)
Arguments
data |
The mapper function's input data frame. |
arg |
Symbol. The quoted input variable, captured by |
description |
String (length 1). Short description of the column in question, to be inserted into an error message. |
Value
The input data frame, data
, possibly modified.
See Also
vignette("consistency-tests-in-depth")
, for context.