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

From: Hadley Wickham <hadley_at_rice.edu>
Date: Sat, 03 Jul 2010 11:17:29 -0500

ink1">Hi Dan,

Is there a reason you can't change the function to

f <- function(x, ...) {}

?

Hadley

On Fri, Jul 2, 2010 at 4:26 PM, Daniel Murphy <chiefmurphy_at_gmail.com> wrote:
> R-Devel:
>
> 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}
>
> but I feared my solution might do some extra copying, with a performance
> penalty if the dotted objects in the actual call to "f' are very large.
>
> I thought the following alternative might avoid a potential performance hit
> by evaluating the attribute in the parent.frame (and therefore avoid extra
> copying?):
>
> f<-function(...)
> {
>   L<-match.call(expand.dots=FALSE)[[2L]]
>   x <- eval(substitute(attr(x,"foo"), list(x=L[[1L]])))
>   if (x=="bar") cbind(...) else x
> }
>
> system.time tests showed this second form to be only marginally faster.
>
> Is my fear about extra copying unwarranted? If not, is there a better way to
> get the "foo" attribute of the first argument other than my two
> alternatives?
>
> Thanks,
> Dan Murphy
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 03 Jul 2010 - 16:25:47 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 Sun 04 Jul 2010 - 09:00: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