Learn R Programming

reproducible (version 0.2.0)

Copy: Recursive copying of nested environments, and other "hard to copy" objects

Description

When copying environments and all the objects contained within them, there are no copies made: it is a pass-by-reference operation. Sometimes, a deep copy is needed, and sometimes, this must be recursive (i.e., environments inside environments).

Usage

Copy(object, filebackedDir = tempdir(), ...)

# S4 method for ANY Copy(object, filebackedDir = tempdir(), ...)

# S4 method for data.table Copy(object, filebackedDir = tempdir(), ...)

# S4 method for environment Copy(object, filebackedDir = tempdir(), ...)

# S4 method for list Copy(object, filebackedDir = tempdir(), ...)

# S4 method for data.frame Copy(object, filebackedDir = tempdir(), ...)

# S4 method for Raster Copy(object, filebackedDir = tempdir(), ...)

Arguments

object

An R object (likely containing environments) or an environment.

filebackedDir

A directory to copy any files that are backing R objects, currently only valid for Raster classes. Defaults to tempdir(), which is unlikely to be very useful.

...

Only used for custom Methods

See Also

.robustDigest

Examples

Run this code
# NOT RUN {
e <- new.env()
e$abc <- letters
e$one <- 1L
e$lst <- list(W = 1:10, X = runif(10), Y = rnorm(10), Z = LETTERS[1:10])
ls(e)

# 'normal' copy
f <- e
ls(f)
f$one
f$one <- 2L
f$one
e$one ## uh oh, e has changed!

# deep copy
e$one <- 1L
g <- Copy(e)
ls(g)
g$one
g$one <- 3L
g$one
f$one
e$one

# }

Run the code above in your browser using DataLab