[R] Is there a test for .Alias?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Aug 2 20:08:12 CEST 2001


"Henrik Bengtsson" <hb at maths.lth.se> writes:

> Thanks for your quick reply!
> 
> I know you have said it before (r-help list, March 23, 2001): .Alias "should
> not be used", but... is it not even "allowed" in cases where you have a
> function modifying one single element in a HUGE data frame? I know that you
> know about this, but if you are not using .Alias and trying to do the
> following on a small system you will run out of memory and/or it take a long
> time:
> 
> foo <- function(x) {
>   x$a[1] <- x$a[1] + 1
>   x
> }
> 
> bar <- function(x) {
>   x <- .Alias(x)
>   x$a[1] <- x$a[1] + 1
> }

Not exactly in nice style, but

baz<-function(x)eval.parent(substitute(x$a[1] <- x$a[1] + 1))

is as fast as bar(), and at least it is well-defined what it should do

> system.time(baz(df))
[1] 0 0 0 0 0


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list