rs {FastXML}R Documentation

Functions controlling reference semantics.

Description

rs enables or disables reference semantics for a given object.

is.rs checks whether the given object has forced reference semantics. Note that inherent reference semantics is ingored, so environments and external pointers will strill return FALSE unless rs was used to force it.

copy creates a deep copy of an object regardless if its forced semantics. However, it does so in the same manner as R without RSO would do (external pointers and environemnts are not copied).

Usage

rs(x, enable = TRUE)
is.rs(x)
copy(x)

Arguments

x

object

enable

logical vector of length one. If TRUE reference semantics of the object is enabled, if FALSE then disabled.

Details

Reference semantics objects are objects that are never duplicated. This can be useful to save memory and to implement mutable objects. However, use with caution and be aware of the dangers, because passing such objects to functions can have side-effects outside the function which is usually unexpected.

Value

rs returns x

is.rs returns TRUE if the object has reference semantics enables, FALSE otherwise.

Note

R has to be compiled with RSO support in order for rs to work. You can easily check whether RSOs are supported using is.rs(rs(1)) since it will be TRUE if RSO is enabled, FALSE otherwise.

Examples

if (!is.rs(rs(1))) # if this returns FALSE then your R does not support RSO
  cat("WARNING: Your R does NOT support RSO.")

a <- 1:10
rs(a)
b <- a
a[1] <- 0
b
is.rs(b)
f <- function(x) x[1] <- 10
f(b)
a

[Package FastXML version 0.1-0 Index]