

   .Alias {base}                                R Documentation

   CCrreeaattee AAlliiaass ((PPooiinntteerr)) ttoo RR OObbjjeecctt

   DDeessccrriippttiioonn::

        `.Alias' creates an alias to another (part of) an R
        object which is more (memory-) efficient than usual
        assignment.

   UUssaaggee::

        new <- .Alias(expr)

   AArrgguummeennttss::

       expr: an R expression; typically a name.

        new: new name by which `expr' can be accessed.

   VVaalluuee::

        an identical copy of `expr'.

   WWAARRNNIINNGG::

        This has a dangerous semantic, and consequences can be
        unexpected (it can be used to defeat the call-by-value
        illusion).  Know what you are doing before using
        `.Alias'!

   SSeeee AAllssoo::

        `<-' for usual assignments.

   EExxaammpplleess::

        mop <- options()
        mop$browser <- "a browser"   # not set on all platforms
        Op <- .Alias(mop)
        ## A change to mop is reflected in Op and vice versa
        ## -- ONLY if no new slots are created ...
        mop$digits <- "Wow!"
        Op$browser <- "another one"
        mop$browser; Op$digits
        all(names(mop) == names(Op) &
            sapply(seq(mop), function(i) all(Op[[i]] == mop[[i]])))
        ##> TRUE -- Op and mop ARE the same thing !

        mop$newslot <- pi #--->> 'newslot' ==> (shallow) COPY of 'mop'
        Op$newslot # R: still the old one, i.e. NULL
        all(names(mop) == names(Op))# no longer TRUE

