It is suggested, that function calls inside R-package functions should preferably use standard evaluation (see here), especially to avoid utils::globalVariables
.
If I'm using non-standard evaluation with the dplyr package, what would be the "translation" into standard evaluation for the following code-snippet - especially for the table
-command?
grp
and dep
are numeric values of the data frame mydf
, while x
is a factor.
Non-standard evaluation:
pvals <- mydf %>%
dplyr::group_by(grp) %>%
dplyr::summarise(N = n(),
p = suppressWarnings(stats::chisq.test(table(x, dep))$p.value))
Standard evaluation?
pvals <- mydf %>%
dplyr::group_by_("grp") %>%
dplyr::summarise_(N = n(),
p = suppressWarnings(stats::chisq.test(table("x", "dep"))$p.value))
And, what about function calls with ggplot
? Does ggplot
have standard-evaluation support?
Edit: Added reproducible example.
library(dplyr)
data(ChickWeight)
ChickWeight %>%
dplyr::group_by(Diet) %>%
dplyr::summarise(N = n(),
p = suppressWarnings(stats::chisq.test(table(weight, Time))$p.value))