Learn R Programming

rv (version 1.0)

rvattach: Attach components of rv objects to search path

Description

rattach works like attach but removes objects from .GlobalEnv that have conflicting names; optionally can also impute vector components by name into the object that is in .GlobalEnv (copying the imputed object into the attached list. rvattach first splits a named vector into a list, and then uses rattach to attach them to the search path.

Usage

rattach(what, name=deparse(substitute(what)), overwrite=TRUE, impute=FALSE, ...)
  rvattach(what, name=deparse(substitute(what)), overwrite=TRUE, impute=FALSE, ...)

Arguments

what
an rv object to be split up into a list of sub-vectors and attached
name
name to use for the attached database. All databases with the exact same name in the search path are removed first.
overwrite
If TRUE, objects with identical names in the workspace (.GlobalEnv) that are masking objects in the database to be attached will be deleted.
impute
If TRUE, the components of each sub-vector are imputed into the object with identical name in the workspace and saved into the list. The object in the workspace is not affected (unless overwrite=TRUE).
...
further arguments passed to attach

Details

rvattach takes an rv object, splits it up into a list of sub-vectors (using split.rv) by their name attributes and attaches the list to the search path. For example, if the object to be processed has names x[1] and y[3], this will be split into a list of two sub-vectors, x and y, and then attached.

If the option impute is TRUE, the corresponding variables with the same names are merged with the ones that are found in .GlobalEnv, and copied into the database.

If the option overwrite is TRUE, the objects with identical names in the Workspace are deleted.

All databases with the exact same name in the search path are removed first.

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

Examples

Run this code
# Trying rattach:
  x <- rvnorm(9)
  names(x) <- paste("theta[", 1+seq_along(x), "]", sep="")
  L <- list(x=x)
  x <- 1:10
  rattach(L, impute=TRUE) # attaches a list called 'rattach' containing an object 'x'
  print(x)
  rattach() # Detaches the list 'rattach'
  exists("x") # FALSE
  # Trying rvattach:
  rvattach(L$x) # attaches a list 'rvattach' containing an object 'theta'
  print(theta)
  rvattach() # Detaches the list 'rvattach'
  exists("theta") # FALSE

Run the code above in your browser using DataLab