I have a function that I want to pass a function to. However, I can't seem to get it to work using the tidy_eval context.
Here is some data:
df <- tribble(
~A, ~B,
"hi", "hello",
"bye", "later"
)
I want to be able to call the function like so:
my_quoting_fn(df, A, str_detect(., pattern = "h*"))
where the third parameter can be any different function.
Here is my first attempt to write the function:
my_quoting_fn <- function(df, col, func) {
func <- enquo(func)
expr <- quo_get_expr(func)
df %>%
pull({{col}}) %>%
eval(expr)
The above gives the error:
Error in eval(., expr) : invalid 'envir' argument of type 'language'`
If I try:
my_quoting_fn <- function(df, col, func) {
df %>%
pull({{col}}) %>%
{{func}}
I get the error
Error in stri_detect_regex(string, pattern, negate = negate, opts_regex = opts(pattern)) : object '.' not found