Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
splice_df <- function(x, ...) {
  expr <- rlang::enquo(x)
  cols <- lapply(rlang::ensyms(..., .named = TRUE), as.character)
  lapply(cols, function(col_name) {
    rlang::quo(`[[`(!!expr, !!col_name))
  })
}
dplyr::summarise(mtcars,
  n = n(),
  x = sum(hp > 100),
  !!!splice_df(binom::binom.wilson(x, n), mean, lower, upper)
)
##    n  x    mean     lower     upper
## 1 32 23 0.71875 0.5462549 0.8443542
rlang::quo(
  dplyr::summarise(mtcars,
    n = n(),
    x = sum(hp > 100),
    !!!splice_df(binom::binom.wilson(x, n), mean, lower, upper)
  )
)
## <quosure>
## expr: ^dplyr::summarise(mtcars, n = n(), x = sum(hp > 100), mean = ^^binom
##         ::binom.wilson(x, n)[["mean"]], lower = ^^binom::binom.wilson(x,
##           n)[["lower"]], upper = ^^binom::binom.wilson(x, n)[["upper"]])
## env:  global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.