This question is related to the one posted here.
In short I am looking for why base::substitute and rlang::enexpr are behaving differently below.
#works
f1 <- function(x,y){
do.call("methods", list(substitute(x::y)))
}
f1(broom,tidy)
#does not work
#Error: `arg` must be a symbol
f2 <- function(x,y){
do.call('methods',list(rlang::enexpr(x::y)))
}
f2(broom,tidy)
The longer version. In the advanced R book chapter 19 you can see tables 19.1 and 19.2 suggest that enexpr and substitute should serve the same purpose in a function call (I could be wrong here and would be happy with an explanation on why I am wrong).
I decided to test this out and saw that in f1 returns results but f2 returns an error.
Interestingly, if you use do.call('methods',list(rlang::expr(broom::tidy))) this works. I find this interesting because rlang::expr simply calls rlang::enexpr.
In the question above, MrFlick posted this function as a pure rlang solution
#also works
#function from MrFlick in the posted link
f3 <- function(x,y){
x <- rlang::ensym(x)
y <- rlang::ensym(y)
rlang::eval_tidy(rlang::quo(methods(`::`(!!x, !!y))))}
f3(broom,tidy)
This seems to be a bit more complicated than I was expecting.
It would be helpful to know why f1 and f2 are not equivalent or how to make f2 work with enexpr.