I have a much more complicated function but the minimal version of it boils down to the following where I need to convert the entered function by the user to a character. But I can't figure out how to do this (I've also tried a bunch of rlang
hacks that didn't work).
foo <- function(.f) {
if (as.character(.f) == "stats::lm") {
print("this is lm")
} else {
print("this is not lm")
}
}
foo(stats::lm)
#> Error in as.character(.f): cannot coerce type 'closure' to vector of type 'character'
How can I do this?