Dots (…) with variable title

Question:

I need to run a function like

f <- function(...) {
  l <- list(...)
  l[["hortela"]]
}

x <- 'hortela'

if we do

f(hortela = 1)

we have the result 1 , which is expected.

How do I call f() using x instead of writing hortela manually?

PS: I don't want to modify f() .

Answer:

I managed to solve it using do.call and a named list.

do.call(f, setNames(list(1), x))

does the work.

Scroll to Top