Dots (...) with variable name

Asked

Viewed 53 times

3

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, what is expected.

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

PS: I don’t want to change the f().

1 answer

2


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

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

does the work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.