Passing arguments with dots to eval_tidy

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?

alter your wrapper function to this :

wrapper_func <- function(first_name = "John", last_name = "Doe") {
  inside_func(operation_a(firstName,lastName),
              firstName = first_name,
              lastName = last_name
  )
}

Thanks! Can you help me understand how does this solves the problem?

eval_tidy was literally calling the expression operation_a() just like that, i.e. it was being asked to not use arguments. I altered it to evaluate operation_a(firstName,lastName)

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.