with_pro {tinycodet} | R Documentation |
Standard Evaluated Versions of Some Common Expression-Evaluation Functions
Description
The with_pro()
and aes_pro()
functions
are standard-evaluated versions of the expression-evaluation functions
with and ggplot2::
aes,
respectively.
These alternative functions are more programmatically friendly:
They use proper standard evaluation,
through the usage of one-sided formulas,
instead of non-standard evaluation,
tidy evaluation,
or similar programmatically unfriendly evaluations.
Usage
with_pro(data, form)
aes_pro(...)
Arguments
data |
a list, environment, or data.frame. |
form |
a one-sided formula giving the expression to evaluate in |
... |
arguments to be passed to |
Details
The aes_pro()
function is the standard evaluated alternative to
ggplot2::
aes.
Due to the way aes_pro()
is programmed,
it should work even if the tidy evaluation technique
changes in 'ggplot2'.
To support functions in combinations with references of the variables,
the input used here are formula inputs, rather than string inputs.
See the Examples section below.
Value
For with_pro()
: see with.
For aes_pro()
: see ggplot2::
aes.
Non-Standard Evaluation
Non-Standard Evaluation (sometimes abbreviated as "NSE"),
is somewhat controversial.
Consider the following example:
aplot <- "ggplot2" library(aplot)
What package will be attached? It will not be 'ggplot2',
nor will an error occur.
Instead, the package 'aplot' will be attached.
This is due to evaluating the expression 'aplot' as a quoted expression,
instead of evaluating the contents (i.e. string or formula) of the variable.
In other words: Non-Standard Evaluation.
Regular Standard Evaluation does not have the above problem.
Note
The with_pro()
function, like the original with function,
is made for primarily for convenience.
When using modelling or graphics functions with an explicit data
argument
(and typically using formulas),
it is typically preferred to use the data
argument of that function,
rather than to use either
with(data, ...)
or with_pro(data, ...)
.
See Also
Examples
requireNamespace("ggplot2")
d <- import_data("ggplot2", "mpg")
# mutate data:
myform <- ~ displ + cyl + cty + hwy
d$mysum <- with_pro(d, myform)
summary(d)
# plotting data:
x <- ~ cty
y <- ~ sqrt(hwy)
color <- ~ drv
ggplot2::ggplot(d, aes_pro(x, y, color = color)) +
ggplot2::geom_point()