.Alias                 package:base                 R Documentation

_C_r_e_a_t_e _A_l_i_a_s (_P_o_i_n_t_e_r) _t_o _R _O_b_j_e_c_t

_D_e_s_c_r_i_p_t_i_o_n:

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

_U_s_a_g_e:

     new <- .Alias(expr)

_A_r_g_u_m_e_n_t_s:

    expr: an R expression; typically a name.

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

_V_a_l_u_e:

     an identical copy of `expr'.

_W_a_r_n_i_n_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_e_e _A_l_s_o:

     `<-' for usual assignments.

_E_x_a_m_p_l_e_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

