do.call with function from package?

Hey everyone!

I am writing a function that uses some of Rs metaprogramming facilities, including constructing a function call using do.call and a list of arguments.

An issue that has come up is that if i want to include my function in a package, i should refer to functions using namespace::function, rather than importing the package directly. However, do.call("namespace::package",...) does not work. How do i do.call (or call for that matter), with foreign functions inside a package?

Thanks!
P

Hi @peder2911,

I found that this works, but looks inelegant and uses quosures, I am sure a better way exists (just using as an example one of the examples in the do.call documentation):

library(rlang)
f_name = quo(base::paste)
tmp <- expand.grid(letters[1:2], 1:3, c("+", "-"))
q <- quo(do.call(!!f_name, c(tmp, sep = "")))
eval_tidy(q)

Hey! Thank you for your answer.
Sorry, i wasn't thinking this through: I forgot that do.call doesn't exclusively take string-arguments but can also be passed a function. This means i can just pass it namespace::function. :sweat_smile:

Thanks again!
P

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