Function with optional argument for data, non-standard eval?

I am working on making a package: https://meghapsimatrix.github.io/simhelpers/index.html

My advisor suggested this:
"It seems like it would be useful to allow the calc_*() functions to operate either on variable names, within a data.frame as specified in res_dat, or _directly on vectors. Paired with dplyr 1.0, the latter would then circumvent the need for do() and allow for the following syntax:"

results %>%
    group_by(method) %>%
    mutate(calc_rejection(p_values = p_val))

"I think there is probably a way to write it so that the res_dat argument
is optional. See the chapter on non-standard evaluation in Hadley's
Advanced R book for pointers. If it's optional, then there's no need to
wait for dplyr 1.0."

Right now the function works like this:

# install.packages("devtools")
# devtools::install_github("meghapsimatrix/simhelpers")
library(simhelpers)
library(tidyverse)

welch_res %>%
  group_by(n1, n2, mean_diff, method) %>%
  group_modify(~ calc_rejection(.x, p_values = p_val)) %>%
  kable(digits = 5)

How do I make the function work on grouped data without needing to use do() or group_modify(). Is it possible??

Here is the source code for the function: https://github.com/meghapsimatrix/simhelpers/blob/master/R/calc_rejection.R

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.