I am having trouble getting rlang::exec() to work when I specify the package for a function call.
Simple examples:
rlang::exec("tibble" , a=1:5) # this fails because package 'tibble' is not yet loaded.
# Error in tibble(a = 1:5) : could not find function "tibble"
library(tibble)
rlang::exec("tibble" , a=1:5) # now it works.
rlang::exec("tibble::tibble" , a=1:5) # this fails.
# Error in `tibble::tibble`(a = 1:5) :
# could not find function "tibble::tibble"
Ultimately, I am looking to include a command like this in an R package that I am making. It would be like this:
foo <- function(stuff , fun , args) {
# do stuff, and then:
rlang::exec(fun , !!!args)
# do more stuff.
}
and I want the user to be able to pass a function from a specific package. Something like this:
foo(stuff = whatever , fun = "pkg::fun" , args = list(a=1,b=2) )
And the user should be able to do that without first loading package pkg, right?