# converting items in a list in global variables
source("VLP.R")

well <- well.params()                   # list of well parameters

for (item in names(well)) {
    #print(item)
    cat(item, "\n")
    print(well[[item]])  
    assign(item, well[[item]])          # make list member globals
} 
# save an R object in a RDATA file and retrieve it in a new environment
# to avoid collision with global objects

load("./data/well02.rda")             # load any data

rdata.file <-  "./data/mymodel.Rdata"  # name of new file 

save(well.data, file = rdata.file)               # save the data to a RDA file
load(rdata.file, envir = new <- new.env())       # load the RDA file in environment `new`


identical(well.data,                             # test if both variable are the same
          new$well.data,                         # new is another environment
          ignore.environment = TRUE)
# list whatever is in the `new` environment
new$well.data

Source: http://www.fromthebottomoftheheap.net/2012/04/01/saving-and-loading-r-objects/

# Retrieve objects in RData files and asign them to variables equal
# to the name of the file

setwd("./data")                          # set working directory to ./data

filelist = list.files(pattern = ".rda")   # extract .RData files from working directory

# determine unique names to assign to the objects 
# (this solution is based on the file name)
names <- make.names(sapply(strsplit(filelist, split="_"),"[[",1))

# read in objects, giving each a unique name
list2env(lapply(setNames(filelist, names), function(x) get(load(x))), 
         envir = .GlobalEnv)


f0nzie/rNodal documentation built on May 6, 2019, 10:14 a.m.