On 30.01.2011 17:38, Tal Galili wrote:
Hello all, I would like to extract the variable name passed into a specific argument of a function. Using match.call() will give me a list of arguments and what was passed into them, but I couldn't find how to get a particular argument out of it (at least without using some string manipulation). Here is an example (in it, my objective is to know what is the variable name assigned to the argument "b"): foo<- function(a, b, c) { print(match.call())
Replace by print(substitute(b)) Uwe Ligges
} x = 1 ; y = 1 foo(x, y) # here the answer should be "y" foo(c= x, y) # here the answer should be "" (or NULL/NA) Any suggestion on how to do this? BTW, the purpose of this is to be able to avoid the error produced by, for example, this: yy<- data.frame(y = 1:10, x = 1:10) plot(y, data = yy) # error plot(y~x, data = yy) # no error... Thanks, Tal ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- [[alternative HTML version deleted]] ______________________________________________ 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.
______________________________________________ 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.