Why do I need quosures?
User environment:
Package foo:
bmi <- function(mass, height) {
mass / height^2
}
summarise_bmi <- function(data, mass, height) {
data %>%
bar::summarise_stats(bmi({{ mass }}, {{ height }}))
}
Package bar:
check_numeric <- function(x) {
stopifnot(is.numeric(x))
x
}
summarise_stats <- function(data, var) {
data %>%
dplyr::transmute(
var = check_numeric({{ var }})
) %>%
dplyr::summarise(
mean = mean(var, na.rm = TRUE),
sd = sd(var, na.rm = TRUE)
)
}
All add up to…
With each tab over indicating a quosure boundary
- You need to make sure that
mass
andheight
stay properly tracked throughout environments