on 07/20/2008 08:42 AM willemf wrote:
Does anyone know of good reading material about the following? The R language
definition does not appear to explicitly address my problem (maybe I misread
that document?)
I have a function definition:
func(a)
cat("Anova for variable ",a)
What I wish to achieve is to call func with a value such as:
func(Age)
and then obtain:
Anova for variable Age
Using "names(formals())" inside function func yields "a". That is not what I
need. I need the name contained in a, which in this case is Age.
Thanks for your time.
Willemf
MyFun <- function(a) {
cat("Anova for variable", deparse(substitute(a)), "\n")}
Age <- 50:60
> MyFun(Age)
Anova for variable Age
The deparse(substitute(...)) idiom is what you are looking for.
See ?deparse and ?substitute
HTH,
Marc Schwartz
______________________________________________
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.