Re: [Rd] Attributes of 1st argument in ...

From: Olaf Mersmann <olafm_at_kimberly.tako.de>
Date: Sat, 03 Jul 2010 00:15:57 +0200

Hi Daniel,

On 02.07.2010, at 23:26, Daniel Murphy wrote:
> I am trying to get an attribute of the first argument in a call to a
> function whose formal arguments consist of dots only and do something, e.g.,
> call 'cbind', based on the attribute
> f<- function(...) {get first attribute; maybe or maybe not call 'cbind'}
>
> I thought of (ignoring "deparse.level" for the moment)
>
> f<-function(...) {x <- attr(list(...)[[1L]], "foo"); if (x=="bar")
> cbind(...) else x}

what about using the somewhat obscure ..1 syntax? This version runs quite a bit faster for me:

 g <- function(...) {
   x <- attr(..1, "foo")
   if (x == "bar")
     cbind(...)
   else
     x
 }

but it will be hard to quantify how this pans out for your unless we know how many and what size and type the arguments are.

Cheers,
Olaf



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 02 Jul 2010 - 22:18:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 03 Jul 2010 - 06:50:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive