Witold E Wolski
2013-Aug-14 09:52 UTC
[R] storing multidimensional arrays - save and load -
I am have a procedure which generates multidimensional arrays. To compute them is expensive so I want to store them in order to be able to analyse them later. I am using at the moment problem is that the array is always assigned to a variable ma (the computation is in a loop). Than I generate a file name and store it (i.e) save(ma, file="ma1.txt") save(ma, file="ma2.txt") ... problem starts when I want to load it load("ma1.RData") # loads in ma load("ma2.RData") # overrides ma How can i prevent this behaviour. Is there a better way to store multidimensional arrays? regards -- Witold Eryk Wolski
You can use saveRDS() and readRDS() instead of save/load. Unlike load readRDS just returns the value, allowing you to assign it to whatever name you want. Best, Ista On Wed, Aug 14, 2013 at 5:52 AM, Witold E Wolski <wewolski@gmail.com> wrote:> I am have a procedure which generates multidimensional arrays. > > To compute them is expensive so I want to store them in order to be > able to analyse them later. > > I am using at the moment > > problem is that the array is always assigned to a variable ma (the > computation is in a loop). > Than I generate a file name and store it (i.e) > save(ma, file="ma1.txt") > save(ma, file="ma2.txt") > ... > > > problem starts when I want to load it > load("ma1.RData") # loads in ma > load("ma2.RData") # overrides ma > > How can i prevent this behaviour. Is there a better way to store > multidimensional arrays? > > regards > > > -- > Witold Eryk Wolski > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Bretschneider (R)
2013-Aug-15 22:54 UTC
[R] storing multidimensional arrays - save and load -
Dear Witold E Wolski, Re:> I am have a procedure which generates multidimensional arrays. > > To compute them is expensive so I want to store them in order to be > able to analyse them later. > > I am using at the moment > > problem is that the array is always assigned to a variable ma (the > computation is in a loop). > Than I generate a file name and store it (i.e) > save(ma, file="ma1.txt") > save(ma, file="ma2.txt") > ... > > > problem starts when I want to load it > load("ma1.RData") # loads in ma > load("ma2.RData") # overrides ma > > How can i prevent this behaviour. Is there a better way to store > multidimensional arrays? > > regards > > > -- > Witold Eryk WolskiIt would be no problem if you processed one such array at a time, so 1 load("ma1.RData") # loads in ma 2 process array ma and save/print output 3 load("ma2.RData") # overrides ma 4 process array ma (now the new one) and save etc. ... This can be automated by reading the directory contents and make a list of "ma-files", to be processed in a loop. (I can provide an example if you like). Hope this helps, Best wishes, Dr. Franklin Bretschneider Dept of Biology Utrecht Unversity Padualaan 8 3584 CH Utrecht The Netherlands f.bretschneider@uu.nl [[alternative HTML version deleted]]