Description Usage Arguments Examples
Uses the eval_tidy() function to evaluate an expression
within the context of the data
and env
arguments.
It provides two additional elements of flexibility:
data
does not need to be named, if it isn't named, it can be
references by .
or .data
.
expr
can be a function (preferably a fseq
object)
that will be applied to data
. What's more is that expr
will be evaluated through eval_tidy()
before being applied
and so functions defined within data
can also be used.
Note the data
argument is first (whereas in eval_tidy()
, it is
second) to keep in line with the pipeline theme of mpipe
.
1 |
data |
data within which to evaluate. Used as a data mask in |
expr |
a call, function or expression to be evaluated within the context
of |
... |
additional arguments to be attached to |
env |
the environment in which to evaluate the expression |
allow_NULL |
logical. Can |
verbose |
logical. Should |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # Can do simple evaluations of functions on vectors
1:10 %>% eval_expr(mean)
# Or on a variable
x <- 1:10
eval_expr(x, mean)
# or within a data.frame (or tibble)
tbl <- data.frame(x = 1:10)
eval_expr(tbl, mean(x))
# or a list
lst <- list(x = 1:10)
eval_expr(lst, mean(x))
# functions are applied to data
eval_expr(tbl, nrow)
# but they are evaluated within data first
lst <- c(fun = mean, lst)
eval_expr(lst, fun(x))
# additional named arguments can be passed in too
tbl %>%
eval_expr(mean(x + y), y = 5)
x %>%
eval_expr(. %>% magrittr::add(y) %>% mean(), y = 5)
# Environment scope:
lst <- list(x = 1:3, y = 1)
y <- 4
e1 <- new.env(parent = emptyenv())
e1$y <- 3
# additional arguments in data take priority over others
eval_expr(lst, y, y = 2, env = e1)
lst$y <- NULL
# then the ... argument:
eval_expr(lst, y, y = 2, env = e1)
# then in env
eval_expr(lst, y, env = e1)
# without env, the calling environment is used
eval_expr(lst, y)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.