Dear R-users, I need to load outputs from multiple previous calculations into one R session for comparison and (cross-)analysis. The previous calculations are stored in different directories in .Rdata files (I don't know if this is the best storage for later usage, but the previous project could be recalculated and saved into different format, if needed, potentially.) I can load consequently multiple .Rdata files (in which variable names are identical), but I don't know how to preserve variables from these files or make them unique. I would imagine pointing them as in a list: # loading 2, max. 4 outputs of previous calculations load(DataSet1) # VariableA is present load(DataSet2) # VariableA is present, too # both VraiableA listed and present DataSet1$VariableA$parameters DataSet2$VariableA$parameters But what is the way to feed all variables into a list? Or more generally, what is an efficient way to work with multiple separate outputs which one would like to compare? (I have read something about environments, but I understood it's only for functions. I could create environments, but was not succesful in using them at all (location change or separate sandbox). Functions saveCache, loadCache, saveObject, loadObject is not really what I have in mind, too -- saveObject(list=ls(), "NewObjectFile") is not a solution either...) Thanks for any hint in advance. Cheers, Zroutik [[alternative HTML version deleted]]
Duncan Murdoch
2009-Jul-15 09:41 UTC
[R] loading multiple .Rdata and preserving variable names
On 15/07/2009 5:00 AM, ?rout?k wrote:> Dear R-users, > > I need to load outputs from multiple previous calculations into one R > session for comparison and (cross-)analysis. The previous calculations are > stored in different directories in .Rdata files (I don't know if this is the > best storage for later usage, but the previous project could be recalculated > and saved into different format, if needed, potentially.) > > I can load consequently multiple .Rdata files (in which variable names are > identical), but I don't know how to preserve variables from these files or > make them unique. > > I would imagine pointing them as in a list: > > # loading 2, max. 4 outputs of previous calculations > load(DataSet1) # VariableA is present > load(DataSet2) # VariableA is present, too > > # both VraiableA listed and present > DataSet1$VariableA$parameters > DataSet2$VariableA$parameters > > But what is the way to feed all variables into a list? Or more generally, > what is an efficient way to work with multiple separate outputs which one > would like to compare? > > (I have read something about environments, but I understood it's only for > functions. I could create environments, but was not succesful in using them > at all (location change or separate sandbox). Functions saveCache, > loadCache, saveObject, loadObject is not really what I have in mind, too -- > saveObject(list=ls(), "NewObjectFile") is not a solution either...)Environments are basic in R. If they are "only for functions", it's because everything in R is done by functions. Given two .RData files, you can load them into separate environments. Dealing with conflicting variables names is another issue, of course. For example: DataSet1 <- new.env() load( "somefile", envir=DataSet1) Now use ls(DataSet1) to see what you've got, repeat for DataSet2, etc. You can get a variable as DataSet1$VariableA. Duncan Murdoch> > Thanks for any hint in advance. > > Cheers, Zroutik > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.