I want to use a wrapper function around another function that takes a function as first argument and other arguments as ellipses. I want to use rlang
to evalute the function with the arguments passed as dots and return the results. However, the evaluation cannot find the parameters passed.
library(rlang)
# Wrapper function
wrapper_func <- function(first_name = "John", last_name = "Doe") {
inside_func(operation_a(),
firstName = first_name,
lastName = last_name
)
}
# Method function
inside_func <- function(f, ...) {
call_parameters <- rlang::list2(...)
f_quote <- rlang::enexpr(f)
rlang::eval_tidy(f_quote, data = call_parameters)
}
# Operation (there will be others in the package that I am working on)
operation_a <- function(firstName, lastName) {
paste(firstName, lastName)
}
# Running the function
wrapper_func(first_name = "Ryou", last_name = "Surendra")
Running debug it seems like that the data parameter is not passed to the function in eval_tidy
. Am I doing this totally wrong?