[R] Is there a test for .Alias?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 2 21:06:52 CEST 2001


On Thu, 2 Aug 2001, Henrik Bengtsson wrote:

> 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
> }
>
> df <- data.frame(a=rep(0,1e6))
> object.size(df)            # 20,000,356 bytes
>
> gc()
> m0 <- memory.size()
> system.time(df <- foo(df)) # NA NA 29.45 NA NA
> m1 <- memory.size()
> m1-m0                      # 24,000,224 bytes (!!!)
>
> gc()
> m0 <- memory.size()
> system.time(bar(df)) # NA NA 0 NA NA
> m1 <- memory.size()
> m1-m0                      # 72 bytes
>
> I have seen on at least two different WinMe systems with default virtual
> memory setup ("Lets Windows manage my virtual settings. (Recommended)") and
> with clean [R] installations that the maximum memory limit for [R] is the
> size of the RAM (the full, not the available). I believe this is what most

It's the default, but you can change it: see ?Memory on Windows.

> Windows are setup as. I am myself aware of this and my machine has a large
> RAM so for me it is not a problem, but I am writing a package that will be
> used by people with less computer skills and by experience I know that
> people will just stop using something that gives an error and it doesn't
> matter how great the package is.
>
> This is why I am eager to use .Alias (or something else). However, if .Alias
> is a "dead end" I wont use it. I can see different reasons for not using
> .Alias, such as (1) strange behavior, (2) .Alias is not well defined, (3)
> not compatible with S-Plus (?). I am also aware of thing like object.size(x)
> will turn 'x' into a copy if 'x' was aliased.
>
> Grateful for all help!
>
> Henrik Bengtsson
> Statistics Dept.
> Lund University/UC Berkeley
> hb at maths.lth.se
>
> > -----Original Message-----
> > From: Thomas Lumley [mailto:tlumley at u.washington.edu]
> > Sent: Thursday, August 02, 2001 8:29 AM
> > To: Henrik Bengtsson
> > Cc: r-help at stat.math.ethz.ch
> > Subject: Re: [R] Is there a test for .Alias?
> >
> >
> > On Wed, 1 Aug 2001, Henrik Bengtsson wrote:
> >
> > > Is there a way to check if a variable is aliases to another? Example:
> > >
> > >   x <- list(a=1, b=2, c=3)
> > >   y <- .Alias(x)
> > >
> > > Can one tell that 'y' is an alias to another object? By the way, is it a
> > > correct statement to say that 'y' is aliased TO 'x', or is both
> > 'x' and 'y'
> > > said to be aliased to an internal object?
> >
> > The correct statement is that, since .Alias shouldn't be used, 'y' is not
> > aliased to 'x'.
> >
> > You can't tell except in internal C code by checking that the objects are
> > pointers to the same place.
> >
> >
> > 	-thomas
> >
> > Thomas Lumley			Asst. Professor, Biostatistics
> > tlumley at u.washington.edu	University of Washington, Seattle
> >
> >
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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