Jenny Barnes
2006-Nov-23 13:35 UTC
[R] reaccessing array at a later date - trying to write it to file
Dear R-help community I am trying to write an R object (data.out) to a file in order to re-access it later and not have to re-load up the array with data every time. Here is the form of data.out> data.out <- list(lats=seq(88.542, -88.542, length=94),lons=seq(0, 360-1.875, length=192), date=vector(length=nyr*12), data=array(NA, c(nyr*12, 94*192)) ) I tried> save(data.out, file="/home/jenny/data/data.out.RData", ascii=TRUE) andcombination of ways to re-access it but I couldn't reaccess it and therefore use the data within. I then tried> dput(data.out,file="/home/jmb/sst_precip/gribdata/data.out.RData",control="showAttributes") #but the associated dget seemed to freeze my terminal window up and took much too long (I gave up after about 15 minutes) to read this file. Does anybody have an idea about another way (or a way within these methods) to come back to my data within the list data.out (with all of its associated data.out$lats, data.out$lons, data.out$date, data.out$data) at a later stage to use the data within it to actually get on with some analysis? I appreciate your time in reading this and look forward to hearing any suggestions, Sincerely, Jenny Barnes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jennifer Barnes PhD student - long range drought prediction Climate Extremes Department of Space and Climate Physics University College London Holmbury St Mary, Dorking Surrey RH5 6NT 01483 204149 07916 139187 Web: http://climate.mssl.ucl.ac.uk
Prof Brian Ripley
2006-Nov-23 14:06 UTC
[R] reaccessing array at a later date - trying to write it to file
On Thu, 23 Nov 2006, Jenny Barnes wrote:> Dear R-help community > > I am trying to write an R object (data.out) to a file in order to re-access it > later and not have to re-load up the array with data every time. Here is the > form of data.out > >> data.out <- list(lats=seq(88.542, -88.542, length=94), > lons=seq(0, 360-1.875, length=192), > date=vector(length=nyr*12), > data=array(NA, c(nyr*12, 94*192)) > ) > > I tried >> save(data.out, file="/home/jenny/data/data.out.RData", ascii=TRUE) and > combination of ways to re-access it but I couldn't reaccess it and therefore use > the data within.What stopped you re-accessing it? I would use save(data.out, file="/home/jenny/data/data.out.RData") .... load("/home/jenny/data/data.out.RData") If that does not work, we need to see the transcript to (perhaps) understand why (and all the usual details about your environment: it is possible to save really large objects that you cannot restore on a 32-bit machine). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Jenny Barnes
2006-Nov-23 14:47 UTC
[R] reaccessing array at a later date - trying to write it to file
Thank you for your response Professor Ripley, Having tried again your suggestion of load() worked (well - it finished, which I assume it meant it worked). However not I am confused as to how I can check it has worked. I typed>data.out$datawhich called up the data from the file - but I'm not sure if this is data from the file I have just restored as in my "previously saved workspace restored" data.out is still there so if I typed data.out$data I wouldn't know if it was coming from the newly loaded file or from previously. Is there an alternative way to check it has loaded properly? Also, is it normal that if I type>data.out.RDatait says Error: object "data.out.RData" not found Here are my details: platform sparc-sun-solaris2.10 arch sparc os solaris2.10 system sparc, solaris2.10 status major 2 minor 3.1 year 2006 month 06 day 01 svn rev 38247 language R version.string Version 2.3.1 (2006-06-01) My computer shouldn't have a problem with dealing with this data.>On Thu, 23 Nov 2006, Jenny Barnes wrote: > >> Dear R-help community >> >> I am trying to write an R object (data.out) to a file in order to re-accessit>> later and not have to re-load up the array with data every time. Here is the >> form of data.out >> >>> data.out <- list(lats=seq(88.542, -88.542, length=94), >> lons=seq(0, 360-1.875, length=192), >> date=vector(length=nyr*12), >> data=array(NA, c(nyr*12, 94*192)) >> ) >> >> I tried >>> save(data.out, file="/home/jenny/data/data.out.RData", ascii=TRUE) and >> combination of ways to re-access it but I couldn't reaccess it and thereforeuse>> the data within. > >What stopped you re-accessing it? I would use > >save(data.out, file="/home/jenny/data/data.out.RData") >.... >load("/home/jenny/data/data.out.RData") > >If that does not work, we need to see the transcript to (perhaps) >understand why (and all the usual details about your environment: it is >possible to save really large objects that you cannot restore on a >32-bit machine). > >-- >Brian D. Ripley, ripley at stats.ox.ac.uk >Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ >University of Oxford, Tel: +44 1865 272861 (self) >1 South Parks Road, +44 1865 272866 (PA) >Oxford OX1 3TG, UK Fax: +44 1865 272595~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jennifer Barnes PhD student - long range drought prediction Climate Extremes Department of Space and Climate Physics University College London Holmbury St Mary, Dorking Surrey RH5 6NT 01483 204149 07916 139187 Web: http://climate.mssl.ucl.ac.uk
Jenny Barnes
2006-Nov-23 16:14 UTC
[R] reaccessing array at a later date - trying to write it to file
Thank you Barry for your time in responding! I think that will really help - the difference between attach and load were not clear to me before your reply! Also I did not know about rm() - thank you for the detail, I know you took longer than you had planned but I do appreciate it, For those with a similar problems in the future please see the responses below:> >Jenny Barnes wrote: > >> Having tried again your suggestion of load() worked (well - it finished,which I>> assume it meant it worked). However not I am confused as to how I can checkit>> has worked. >> I typed >> >>>data.out$data >> >> which called up the data from the file - but I'm not sure if this is datafrom>> the file I have just restored as in my "previously saved workspace restored" > > Remove it from your current workspace: > > > rm(data.out) > > then do the load('whatever') again: > > > load("/some/path/to/data.out.RData") > > then see if its magically re-appeared in your workspace: > > > data.out$data > > But now if you quit and save your workspace it'll be in your workspace >again when you start up. > > So you could consider 'attach' instead of 'load'... > > Remove data.out from your current workspace, save your current >workspace (with 'save()' - just like that with nothing in the >parentheses), then instead of load('/some/path/to/data.out.RData') use: > > > attach('/some/path/to/data.out.RData') > > This makes R search for an object called 'data.out' in that file >whenever you type 'data.out'. It will find it as long as there's not a >thing called 'data.out' in your workspace. So if you do attach(...) and >then do: > > > str(data.out) > > you'll see info about your data.out object, but then do: > > > data.out=99 > > str(data.out) > > you'll see info about '99'. Your data.out is still happily sitting in >its .RData file, its just masked by the data.out we created and set to >99. Delete that, and your data.out comes back: > > > rm(data.out) > > str(data.out) # - your data object again > > The advantage of this is that data.out wont be stored in your current >workspace again. The disadvantage is that you have to do >'attach(...whatever...)' when you start R, and that data.out can be >masked if you create something with that name in your workspace. It is a >handy thing to do if you create large data objects that aren't going to >change much. > >> Also, is it normal that if I type >> >>>data.out.RData >> >> it says >> Error: object "data.out.RData" not found > > Yes, because thats the name of the _file_ on your computer and not the >R object. > > This should be in the R manuals and help files... and I've gone on >much longer than I intended to in this email :) > >Barry~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Jennifer Barnes PhD student - long range drought prediction Climate Extremes Department of Space and Climate Physics University College London Holmbury St Mary, Dorking Surrey RH5 6NT 01483 204149 07916 139187 Web: http://climate.mssl.ucl.ac.uk
Maybe Matching Threads
- problem with loop to put data into array with missing data forsome files
- loop is going to take 26 hours - needs to be quicker!
- upside down image/data
- problem with loop to put data into array with missing data for some files
- Problem installing R onto Solaris 2.10 system - need advice!!!!!