Please see the wrapr
vignette
for some discussion of let and crossing function call boundaries: vignette('wrapr','wrapr')
.
For formal documentation please see https://github.com/WinVector/wrapr/blob/master/extras/wrapr_let.pdf.
Transformation is performed by substitution, so please be wary of unintended name collisions or aliasing.
Something like let
is only useful to get control of a function that is parameterized
(in the sense it take column names) but non-standard (in that it takes column names from
non-standard evaluation argument name capture, and not as simple variables or parameters). So wrapr:let
is not
useful for non-parameterized functions (functions that work only over values such as base::sum
),
and not useful for functions take parameters in straightforward way (such as base::merge
's "by
" argument).
dplyr::mutate
is an example where
we can use a let
helper. dplyr::mutate
is
parameterized (in the sense it can work over user supplied columns and expressions), but column names are captured through non-standard evaluation
(and it rapidly becomes unwieldy to use complex formulas with the standard evaluation equivalent dplyr::mutate_
).
alias
can not include the symbol ".
".
The intent from is from the user perspective to have (if
a <- 1; b <- 2
):
let(c(z = 'a'), z+b)
to behave a lot like
eval(substitute(z+b, c(z=quote(a))))
.
let
deliberately checks that it is mapping only to legal R
names;
this is to discourage the use of let
to make names to arbitrary values, as
that is the more properly left to R
's environment systems.
let
is intended to transform
"tame" variable and column names to "tame" variable and column names. Substitution
outcomes that are not valid simple R
variable names (produced with out use of
back-ticks) are forbidden. It is suggested that substitution targets be written
ALL_CAPS
style to make them stand out.
let
was inspired by gtools:strmacro()
.
Please see https://github.com/WinVector/wrapr/blob/master/extras/MacrosInR.md for a discussion of macro tools in R
.