Antonio, Fabio Di Narzo
2006-Nov-23 15:33 UTC
[R] dumping/loading objects with 'tsp' attribute
Dear all, I'm indirectly faced with the fact that setting the 'tsp' attribute of an object modifies its class definition:> class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) )[1] "ts" "myts" In general, this is of really little (ok, I admit: totally no) interest for me because 'myts' class is added just after assigning the 'tsp' attribute (by calling ts). However, this behaviour gives me troubles when re-loading a previously deparsed object, so that:> x <- ts(1:2) > class(x) <- c("myts", class(x)) > dput( x , "temp.dat") > class(dget("temp.dat"))[1] "ts" "myts"> unlink("temp.dat")In other words, my real problem should be restated as: how to safely dump (and then load) an object which has a (perhaps valid) "tsp" attribute? More generally: can someone suggest me a safer way to dump/restoring R objects? Tnx all, Antonio. -- Antonio, Fabio Di Narzo Ph.D. student at Department of Statistical Sciences University of Bologna, Italy
On Thu, 23 Nov 2006, Antonio, Fabio Di Narzo wrote:> Dear all, > I'm indirectly faced with the fact that setting the 'tsp' attribute of > an object modifies its class definition: >> class( structure(1:2, tsp=c(1,2,1), class=c("myts","ts")) ) > [1] "ts" "myts" > > In general, this is of really little (ok, I admit: totally no) > interest for me because 'myts' class is added just after assigning the > 'tsp' attribute (by calling ts). > However, this behaviour gives me troubles when re-loading a previously > deparsed object, so that: >> x <- ts(1:2) >> class(x) <- c("myts", class(x)) >> dput( x , "temp.dat") >> class(dget("temp.dat")) > [1] "ts" "myts" >> unlink("temp.dat") > > In other words, my real problem should be restated as: how to safely > dump (and then load) an object which has a (perhaps valid) "tsp" > attribute? > More generally: can someone suggest me a safer way to dump/restoring R objects?save/load. ?dput comes with copious warnings about the problems of doing what you are attempting, so I wonder why you are surprised. -- 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