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).
Copy(object, ...)
# S4 method for class 'ANY'
Copy(
object,
filebackedDir,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose"),
...
)
# S4 method for class 'data.table'
Copy(object, ...)
# S4 method for class 'list'
Copy(object, ...)
# S4 method for class 'refClass'
Copy(object, ...)
# S4 method for class 'data.frame'
Copy(object, ...)An R object (likely containing environments) or an environment.
Only used for custom Methods
A directory to copy any files that are backing R objects,
currently only valid for Raster classes. Defaults
to .reproducibleTempPath(), which is unlikely to be very useful.
Can be NULL, which means that the file will not be
copied and could therefore cause a collision as the
pre-copied object and post-copied object would have the same
file backing them.
if using a database backend, drv must be an object that inherits from DBIDriver e.g., from package RSQLite, e.g., SQLite
an optional DBIConnection object, as returned by dbConnect().
Numeric, -1 silent (where possible), 0 being very quiet,
1 showing more messaging, 2 being more messaging, etc.
Default is 1. Above 3 will output much more information about the internals of
Caching, which may help diagnose Caching challenges. Can set globally with an
option, e.g., options('reproducible.verbose' = 0) to reduce to minimal
The same object as object, but with pass-by-reference class elements "deep" copied.
reproducible has methods for several classes.
To create a new Copy method for a class that needs its own method, try something like shown in example and put it in your package (or other R structure).
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)
#> [1] "abc" "lst" "one"
# 'normal' copy
f <- e
ls(f)
#> [1] "abc" "lst" "one"
f$one
#> [1] 1
f$one <- 2L
f$one
#> [1] 2
e$one ## uh oh, e has changed!
#> [1] 2
# deep copy
e$one <- 1L
g <- Copy(e)
ls(g)
#> [1] "abc" "lst" "one"
g$one
#> [1] 1
g$one <- 3L
g$one
#> [1] 3
f$one
#> [1] 1
e$one
#> [1] 1
## To create a new deep copy method, use the following template
## setMethod("Copy", signature = "the class", # where = specify here if not in a package,
## definition = function(object, filebackendDir, ...) {
## # write deep copy code here
## })