batchsmoosh<--methods {mspath} | R Documentation |
Eliminate unnecessary objects from a batch of simulations.
Replaces the left-hand size, x
, by the right-hand side,
val
, if the two are identical. Otherwise replaces parts of
x
by identical parts of val
. May also simply erase bulky
objects from x
if they should be easy to reconstruct.
batchsmoosh(x) <- value # x and value should have same type
Simulations, particularly distributed simulations, tend to produce lots of duplicate information. Sometimes the information is identical from simulation to simulation, but will be represented in different objects. Sometimes the information is simply bulky, such as a simulated data set that can be reproduced given only the random seed.
batchsmoosh
reduces memory use by replacing substantively
identical objects with the same object reference, namely the one on
the right-hand side. It also deletes some bulky information entirely.
It may be wise to preserve one unaltered object to be sure of having sample values for everything.
The function typically operates recursively.
x
to the same object as value
if
identical(x, value)
.x
and value
have corresponding entries at comparable
indices. They must have the same length.# Create simulation results. In real life, the list elements would # be more interesting. data <- runif(200) dosim <- function(i) list(result=runif(1), input=data, run=i) myrun <- lapply(seq(300), dosim) # Note that in a typical distributed scenario, each simulation # result would have a different input object, even though # they would all be substantively identical. # Compress the simulation results # The master object has 2 roles. # First, when substantively identical objects are not the same # object, the value in master will be inserted in all places. # Second, the master preserves all the original values. mymaster <- myrun[[1]] mysmoosh <- function(x) { batchsmoosh(x) <- mymaster x } myrun <- lapply(myrun, mysmoosh) # and preserve one copy of full data myrun[[1]] <- mymaster # myrun is now a reduced memory version of itself