Let's say I have the following function:
sfn <- function(x){
gsub('"', "", deparse(substitute(x)))
}
Then sfn()
returns "mpg"
(for both mpg
and "mpg"
), this is the result I would like to get.
sfn("mpg")
#> [1] "mpg"
sfn(mpg)
#> [1] "mpg"
However, with an external vector it gets ambiguous. Is there a way to get "mpg"
returned (with the same function sfn()
) instead of "x[1]"
? Only an external vector should be used in case the user specifies this (e.g. with a helper function). Like the following example with extvecfn()
to indicate that x
is an external vector:
x <- c("mpg", "cyl")
# Desired output
sfn(extvecfn(x[1]))
#> [1] "mpg"
# Desired output
sfn(x)
#> [1] "x"
Created on 2022-08-24 with reprex v2.0.2