2

I am trying to find a way to use the name of a vector instead of its value in a function.

a_vector <- 1:20
testFun <- function(x = a_vector) {
# Function should return "a_vector" and not 1:20
}

This is similar to what plot() is using by default for xlab where it uses the description of x.

Many thanks for your help.

leparc
  • 133
  • 5

1 Answers1

1

We can use deparse/substitute

testFun <- function(x = a_vector) {
       deparse(substitute(x))
   }

testFun()
#[1] "a_vector"
akrun
  • 874,273
  • 37
  • 540
  • 662