Mark Heckmann
2008-Dec-22 23:16 UTC
[R] Problem in passing on an argument via ... how do I access it?
Hi r-experts, I want to check if a certain argument has been passed on in a function call via ... ftest <- function(x1, ...) { if(hasArg(y2)==TRUE) print(y2) } Now I call the function passing y2 via ... but I cannot access or use the object. ftest(y2= 2, x= 1)> error in print(y2) : object "y2" not foundWhat I am doing wrong here? How can I access the object y2? TIA and Merry Christmas, Mark
David Winsemius
2008-Dec-23 02:54 UTC
[R] Problem in passing on an argument via ... how do I access it?
Try: ftest <- function(x1, ...) { yargs =list(...) ; if (hasArg(y2) == TRUE) print("YES"); return(yargs) } > ftest(2, y2 = 3) [1] "YES" $y2 [1] 3 > yt <- ftest(2, y2=3) [1] "YES" > yt $y2 [1] 3 On Dec 22, 2008, at 6:16 PM, Mark Heckmann wrote:> Hi r-experts, > > > I want to check if a certain argument has been passed on in a > function call > via ... > > ftest <- function(x1, ...) { > if(hasArg(y2)==TRUE) print(y2) > } > > Now I call the function passing y2 via ... but I cannot access or > use the > object. > > ftest(y2= 2, x= 1) > >> error in print(y2) : object "y2" not found > > What I am doing wrong here? How can I access the object y2? > > > TIA and Merry Christmas, > Mark > > ______________________________________________ > R-help at 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.