nwsVariable               package:nws               R Documentation

_C_r_e_a_t_e _a_n _A_c_t_i_v_e _B_i_n_d_i_n_g _f_o_r _a _n_e_t_W_o_r_k_S_p_a_c_e _V_a_r_i_a_b_l_e

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

     'nwsVariable' creates a variable in an R workspace that mirrors a
     variable in a netWorkSpace.  This allows standard R operations
     (get, assign) to be used to share data between R programs running
     on different machines.

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

       ## S4 method for signature 'netWorkSpace':
       nwsVariable(.Object, xName, mode=c('fifo','lifo','multi','single'),env=parent.frame(),force=FALSE,quietly=FALSE)

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

 .Object: a netWorkSpace class object.

   xName: name of variable to be declared.

    mode: mode of the variable, see details.

     env: environment in which to define active binding.

   force: logical; if 'TRUE', an existing binding will be overwritten.

 quietly: logical; if 'TRUE', no warnings are issued.

_D_e_t_a_i_l_s:

     'nwsVariable' is built on top of the R 'makeActiveBinding'
     function.  It is experimental, but we have found that it is very
     useful for introducing people to the concept of netWorkSpace
     variables.  It's not clear that this API is ever preferable to
     'nwsStore', 'nwsFetch', 'nwsFind' for real programs, however.

     The 'mode' of the variable controls what happens when a variable
     is accessed.  If the 'mode' is ''single'', then all accesses use
     the 'nwsFind' operation.  If the 'mode' is ''fifo'',  ''lifo'', or
     ''multi'', then all accesses use the  'nwsFetch' operation.  
     Assigning a value to an 'nwsVariable' always uses the 'nwsStore'
     operation.

_E_x_a_m_p_l_e_s:

       ## Not run: 
     # create a netWorkSpace
     ws = netWorkSpace('nws example')

     # create a variable in the local R workspace that is linked to
     # a netWorkSpace variable
     nwsVariable(ws, 'x', 'single')

     x <- 0
     x <- 999  # overwrites the 0
     x <- 3.14159  # overwrites the 999
     x   # returns 3.14159
     x   # returns 3.14159
     x   # returns 3.14159

     # create a 'fifo' mode variable
     nwsVariable(ws, 'message', 'fifo')

     message <- 1
     message <- 2
     message <- 3
     message  # returns 1
     message  # returns 2
     message  # returns 3
       ## End(Not run)

