nwsVariable {nws} | R Documentation |
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.
## S4 method for signature 'netWorkSpace': nwsVariable(.Object, xName, mode=c('fifo','lifo','multi','single'),env=parent.frame(),force=FALSE,quietly=FALSE)
.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. |
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.
## 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)