[R] Finding name of variable supplied as function argument

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Sat Feb 25 22:13:41 CET 2012


> I could of course do this the tedious way by simply entering
> the name-strings "G1", "G2" as arguments as well as the variable
> names G1, G2, in a call like
>
>   meds3x3(G1,G2,"G1","G2")
>
> But I'd like to simply be able to pick up, within the function,
> the names of the variables that were used as arguments in the
> function call.

does the following help Ted?

test <- function(x) {
  actual <- deparse(substitute(x))
  paste('argument passed was called', actual)
}

test(happy)
test(apple)



More information about the R-help mailing list