On 05/02/2010 10:00 PM, Duncan Murdoch wrote:
...
I've seen this description a couple of times lately, and I think it's
worth pointing out that it's misleading. The deparse(substitute(x))
trick returns the *expression* that was passed to the argument x.
Sometimes that's the name of a variable, but not always, and I think
it's important to distinguish between names that need to be names, and
expressions that can consist of nothing but a name, but can also be
something else.
So this function
f <- function(x) deparse(substitute(x))
will return "1 + 1" if you call it as f(1 + 1).
I'm very glad to know of this, but when I create a toy function like this:
playdep<-function(x) print(str(deparse(substitute(x))))
testvar<-1:5
playdep(testvar)
chr "testvar"
NULL
which is the same as I get with a literal string, and consistent with
the help page for "deparse".
"Turn unevaluated expressions into character strings."
Unless I am mistaken, deparse just returns a string, whether or not it
is the name of a variable.
Jim
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.