While passing in a function into another function, I want the string name of this function. I also want this to work with the {magrittr} pipe operator.
This is very similar to this question. But when I try it with the pipe, it fails.
library(magrittr)
h <- function(func) {
as.character(substitute(func))
}
# Works
h(eval)
#> [1] "eval"
# Doesn't work
eval() %>% h()
#> [1] "."
# Works
eval() %>% substitute() %>% as.character()
#> [1] "eval"
Created on 2021-08-04 by the reprex package (v2.0.0)
What I'm expecting is:
eval() %>% h()
#> [1] "eval"
Can this be done with a single function call and not a chain call like for the last example? I'm using {magrittr} version 2.0.1.