If you only have to use y once then you can use delayedAssign. This
will assign a promise and the promise will not be evaluated until its
used:
> x
Error: object 'x' not found> y
Error: object 'y' not found> x <- y
> x <- 1
> delayedAssign("y", x)
> x <- 2
> y
[1] 2
If that's not good enough you can use makeActiveBinding:
> x <- 1
> makeActiveBinding("y", function() x, .GlobalEnv)
> y
[1] 1> x <- 2
> y
[1] 2
On Sat, Aug 1, 2009 at 10:55 AM, Daniel Haase<dh at haase-zm.de>
wrote:> Hi Everyone,
>
> is there the possibility in R to assign a variable to be an alias of
another
> one?
> Example:
>
> x <- 17
> # assign y to be an alias of x
> y # returns 17
> x <- 4
> y # returns 4
>
> Daniel
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>