[R] write.table equivalent for lists?

Ivan Calandra ivan.calandra at uni-hamburg.de
Mon Jan 10 15:45:35 CET 2011


Why isn't it in R base? Good question... I'm definitely not the one able 
to answer to it!
Maybe someone more involved in the development can?
Ivan

Le 1/10/2011 15:42, Rainer M Krug a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 01/10/2011 03:35 PM, Ivan Calandra wrote:
>> Hi,
>>
>> If I understood you correctly, you can use saveObject()/loadObject()
>> from package R.utils, like this:
> Correct - thanks - that is what I was looking for.
>
> But why is no such function in R base?
>> library(R.utils)
>> saveObject(x, "x.Rbin")
>> rm(x)
>> y<- loadObject("x.Rbin")
>>
>> HTH,
>> Ivan
>>
>> Le 1/10/2011 15:24, Rainer M Krug a écrit :
>> Hi
>>
>> I am writing simulations in R, and quite regularly, I have to save lists
>> and objects to HDD and load it later again.
>>
>> So I am wondering: why is there no function to write lists (and S3, S4
>> objects) onto HDD WITHOUT keeping the name? What I mean is:
>>
>> For data.frames I can use
>>
>> x<- data.frame(x = runif(10))
>> write.table(x, "x.txt)
>> rm(x)
>>
>> y<- read.table("x.txt")
>>
>> to load it into y.
>>
>> But for lists and S3, S4 objects, I have to use save() and load():
>>
>> x<- list(x=1:10, y=letters(1:10))
>> save(x, file="x.rdata")
>> rm(x)
>>
>> load("x.rdata") #1
>> y<- x          #2
>> rm(x)           #3
>>
>> to load it into y.
>> I don't mind the binary of save - what I am really missing is a command
>> which combines lines #1, #2 and #3.
>>
>> I know - I could write my own
>>
>> save.list<- function(x, file) {
>>     save(s, file=file)
>> }
>>
>> load.list<- function(file) {
>>     load(file)
>>     return(x)
>> }
>>
>> which I could then use as:
>>
>> x<- list(x=1:10, y=letters(1:10))
>> save.list(x, "test.rdata")
>>
>> rm(x)
>>
>> y<- load.list("test.rdata")
>>
>> but: why is there not such a function? Am I missing something here?
>>
>> Cheers,
>>
>> Rainer
>>
>> -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
>> Biology, UCT), Dipl. Phys. (Germany)
>>
>> Centre of Excellence for Invasion Biology
>> Natural Sciences Building
>> Office Suite 2039
>> Stellenbosch University
>> Main Campus, Merriman Avenue
>> Stellenbosch
>> South Africa
>>
>> Tel:        +33 - (0)9 53 10 27 44
>> Cell:       +27 - (0)8 39 47 90 42
>> Fax (SA):   +27 - (0)8 65 16 27 82
>> Fax (D) :   +49 - (0)3 21 21 25 22 44
>> Fax (FR):   +33 - (0)9 58 10 27 44
>> email:      Rainer at krugs.de
>>
>> Skype:      RMkrug
> ______________________________________________
> 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.
> - -- 
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Natural Sciences Building
> Office Suite 2039
> Stellenbosch University
> Main Campus, Merriman Avenue
> Stellenbosch
> South Africa
>
> Tel:        +33 - (0)9 53 10 27 44
> Cell:       +27 - (0)8 39 47 90 42
> Fax (SA):   +27 - (0)8 65 16 27 82
> Fax (D) :   +49 - (0)3 21 21 25 22 44
> Fax (FR):   +33 - (0)9 58 10 27 44
> email:      Rainer at krugs.de
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk0rGugACgkQoYgNqgF2egrnPwCfVM3v/pyJdZQ5f9Fd9w9Mnsfm
> dDYAnAgkcuZqcI+QG6YRU2pEui6PvE/Q
> =4j0d
> -----END PGP SIGNATURE-----
>

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php



More information about the R-help mailing list