## Simple usage Example
x <- cbind(1:5, 5:1) # take a matrix or data frame
rx <- refdata(x) # wrap it into an refdata object
rx # see the autoprinting
rm(x) # delete original to save memory
rx[] # extract all data
rx[-1, ] # extract part of data
rx2 <- rx[-1, , ref=TRUE] # create refdata object referencing part of data (only index, no data is duplicated)
rx2 # compare autoprinting
rx2[] # extract 'all' data
rx2[-1, ] # extract part of (part of) data
cat("for more examples look the help pages
")
# Memory saving demos
square.matrix.size <- 1000
recursion.depth.limit <- 10
non.referenced.matrix <- matrix(1:(square.matrix.size*square.matrix.size), nrow=square.matrix.size, ncol=square.matrix.size)
rownames(non.referenced.matrix) <- paste("a", seq(length=square.matrix.size), sep="")
colnames(non.referenced.matrix) <- paste("b", seq(length=square.matrix.size), sep="")
referenced.matrix <- refdata(non.referenced.matrix)
recurse.nonref <- function(m, depth.limit=10){
x <- m[1,1] # need read access here to create local copy
gc()
cat("depth.limit=", depth.limit, " memory.size=", memsize.wrapper(), "\n", sep="")
if (depth.limit)
Recall(m[-1, -1, drop=FALSE], depth.limit=depth.limit-1)
invisible()
}
recurse.ref <- function(m, depth.limit=10){
x <- m[1,1] # read access, otherwise nothing happens
gc()
cat("depth.limit=", depth.limit, " memory.size=", memsize.wrapper(), "\n", sep="")
if (depth.limit)
Recall(m[-1, -1, ref=TRUE], depth.limit=depth.limit-1)
invisible()
}
gc()
memsize.wrapper()
recurse.ref(referenced.matrix, recursion.depth.limit)
gc()
memsize.wrapper()
recurse.nonref(non.referenced.matrix, recursion.depth.limit)
gc()
memsize.wrapper()
rm(recurse.nonref, recurse.ref, non.referenced.matrix, referenced.matrix, square.matrix.size, recursion.depth.limit)
cat("for even more examples look at regression.test.refdata()
")
regression.test.refdata() # testing correctness of refdata functionality
Run the code above in your browser using DataLab