Re: [R] write.table equivalent for lists?

2011-01-10 Thread William Dunlap
serialize() and unserialize() in the base package
should do the job also and are usually quite a bit
faster than dput() and dget().  However, the format
is not easily read by other programs.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

> -Original Message-
> From: r-help-boun...@r-project.org 
> [mailto:r-help-boun...@r-project.org] On Behalf Of Greg Snow
> Sent: Monday, January 10, 2011 12:59 PM
> To: Rainer M Krug; R-help
> Subject: Re: [R] write.table equivalent for lists?
> 
> How about dput and dget in the base package?
> 
> -- 
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.s...@imail.org
> 801.408.8111
> 
> 
> > -Original Message-
> > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> > project.org] On Behalf Of Rainer M Krug
> > Sent: Monday, January 10, 2011 7:24 AM
> > To: R-help
> > Subject: [R] write.table equivalent for lists?
> > 
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
> > 
> > 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:  rai...@krugs.de
> > 
> > Skype:  RMkrug
> > -BEGIN PGP SIGNATURE-
> > Version: GnuPG v1.4.10 (GNU/Linux)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> > 
> > iEYEARECAAYFAk0rFocACgkQoYgNqgF2egoLMgCfQmZFnLx4Olkb55DtLKmuRXYY
> > yvoAnieTY3/CsGM9pqyoownLxgeuaDrd
> > =VOFu
> > -END PGP SIGNATURE-
> > 
> > __
> > 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.
> 
> __
> 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.
> 

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Greg Snow
How about dput and dget in the base package?

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
> project.org] On Behalf Of Rainer M Krug
> Sent: Monday, January 10, 2011 7:24 AM
> To: R-help
> Subject: [R] write.table equivalent for lists?
> 
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> 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:  rai...@krugs.de
> 
> Skype:  RMkrug
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> 
> iEYEARECAAYFAk0rFocACgkQoYgNqgF2egoLMgCfQmZFnLx4Olkb55DtLKmuRXYY
> yvoAnieTY3/CsGM9pqyoownLxgeuaDrd
> =VOFu
> -END PGP SIGNATURE-
> 
> __
> 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.

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Peter Ehlers

On 2011-01-10 07:34, Rainer M Krug wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 01/10/2011 04:27 PM, Ivan Calandra wrote:

I agree that the R-Core team has better things to do than that, but
since it's already there, why not just add it to the base functions?


Agree completely - and R.utils is not such an obscure package which
nobody uses - so that these functions should be quite bug-free.

Rainer



Henrik write excellent code, maintains it well, and
responds quickly. Can't ask for much more.

As to putting this into pkg:base or pkg:utils, Ivan,
have a look at the code of R.utils::loadObject; it's not
quite trivial.

Peter Ehlers

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 01/10/2011 04:27 PM, Ivan Calandra wrote:
> I agree that the R-Core team has better things to do than that, but
> since it's already there, why not just add it to the base functions?

Agree completely - and R.utils is not such an obscure package which
nobody uses - so that these functions should be quite bug-free.

Rainer

> 
> Le 1/10/2011 16:19, Peter Ehlers a écrit :
>> On 2011-01-10 06:45, Ivan Calandra wrote:
>>> 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
>>
>> Well, I suspect that Rainer has been on this list long
>> enough to know the answer:
>>  Because no has convinced R-Core to implement it!
>>
>> While I might _occasionally_ find it useful, I don't
>> mind if R-Core prefer to pursue other language enhancements.
>>
>> Peter Ehlers
>>
>>>
>>> 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?
>> [...snip...]
>>
> 


- -- 
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:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0rJw4ACgkQoYgNqgF2egreYACfTbfDH4E1SadVzq/WoZD9Tw9h
A5EAnREavj5Wy6ru2ALJeKNc8kZPXIlM
=OoKQ
-END PGP SIGNATURE-

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Ivan Calandra
I agree that the R-Core team has better things to do than that, but 
since it's already there, why not just add it to the base functions?


Le 1/10/2011 16:19, Peter Ehlers a écrit :

On 2011-01-10 06:45, Ivan Calandra wrote:

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


Well, I suspect that Rainer has been on this list long
enough to know the answer:
 Because no has convinced R-Core to implement it!

While I might _occasionally_ find it useful, I don't
mind if R-Core prefer to pursue other language enhancements.

Peter Ehlers



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?

[...snip...]



--
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.calan...@uni-hamburg.de

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

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Peter Ehlers

On 2011-01-10 06:45, Ivan Calandra wrote:

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


Well, I suspect that Rainer has been on this list long
enough to know the answer:
 Because no has convinced R-Core to implement it!

While I might _occasionally_ find it useful, I don't
mind if R-Core prefer to pursue other language enhancements.

Peter Ehlers



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?

[...snip...]

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Ivan Calandra
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:  rai...@krugs.de

Skype:  RMkrug

__
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.
- -- 
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:  rai...@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.calan...@uni-hamburg.de

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

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Rainer M Krug
-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:  rai...@krugs.de
> 
> Skype:  RMkrug
>>
__
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.
>>

- -- 
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:  rai...@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-

__
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.


Re: [R] write.table equivalent for lists?

2011-01-10 Thread Ivan Calandra

Hi,

If I understood you correctly, you can use saveObject()/loadObject() 
from package R.utils, like this:


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 :

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0rFocACgkQoYgNqgF2egoLMgCfQmZFnLx4Olkb55DtLKmuRXYY
yvoAnieTY3/CsGM9pqyoownLxgeuaDrd
=VOFu
-END PGP SIGNATURE-

__
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.



--
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.calan...@uni-hamburg.de

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

__
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.


[R] write.table equivalent for lists?

2011-01-10 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

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:  rai...@krugs.de

Skype:  RMkrug
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0rFocACgkQoYgNqgF2egoLMgCfQmZFnLx4Olkb55DtLKmuRXYY
yvoAnieTY3/CsGM9pqyoownLxgeuaDrd
=VOFu
-END PGP SIGNATURE-

__
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.