Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Henrik Bengtsson
I use: foo - function(...) { args - list(...); names(args); } /Henrik On 6/1/07, Mike Meredith [EMAIL PROTECTED] wrote: Is there a tidy way to get the names of objects passed to a function via the ... argument? rbind/cbind does what I want: test.func1 - function(...) { nms -

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Mike Meredith
Thanks, Henrik, but 'foo' doesn't do what I want: x - some stuff second - more stuff foo(first=x, second) [1] first Brian's right: ...he wants the argument name if there is one otherwise the deparsed argument value, but clarification would be helpful. The function using this compares

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Prof Brian Ripley
On Fri, 1 Jun 2007, Henrik Bengtsson wrote: I use: foo - function(...) { args - list(...); names(args); } But that does not do what was asked: it gets the argument names, not the object names. (Did you actually try it?) It looks from the example that he wants the argument name if

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Gabor Grothendieck
See: http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2242.html which we can modify slightly for the case in question like this: f - function(...) { x - list(...) if (is.null(names(x))) names(x) - names(x)[names(x) == ] - NA mc - match.call()[-1]

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Prof Brian Ripley
How about foo - function(...) { m - as.list(match.call(expand.dots=TRUE))[-1] nm - names(m) for(i in seq_along(m)) if(!nchar(nm[i])) nm[i] - deparse(m[[i]]) nm } Such things are hard to do from R level, hence the use of match.call to do it at C level. On Fri, 1 Jun 2007, Mike

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Mike Meredith
Thanks very much to all of you. It looks like 'match.call' is the key, and both Brian's and Gabor's solutions work fine. --- Mike. -- View this message in context: http://www.nabble.com/Getting-names-of-objects-passed-with-%22...%22-tf3850318.html#a10913978 Sent from the R help mailing list

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Gabor Grothendieck
On 6/1/07, Mike Meredith [EMAIL PROTECTED] wrote: Thanks very much to all of you. It looks like 'match.call' is the key, and both Brian's and Gabor's solutions work fine. --- Mike. Brian's is shorter but I think the one in my post is a bit more robust: f1 - function(...) { +m -

Re: [R] Getting names of objects passed with ...

2007-06-01 Thread Mike Meredith
Sorry, I responded a bit too hastily last night, without testing the two functions properly. Brian's is shorter but I think the one in my post is a bit more robust: Indeed! 'f1' only works if at least one of the arguments is named. Otherwise 'nm' is NULL and 'nchar(nm[i])' fails. 'f2' seems to

[R] Getting names of objects passed with ...

2007-05-31 Thread Mike Meredith
Is there a tidy way to get the names of objects passed to a function via the ... argument? rbind/cbind does what I want: test.func1 - function(...) { nms - rownames(rbind(..., deparse.level=1)) print(nms) } x - some stuff second - more stuff test.func1(first=x, second) [1] first second