Re: [Rd] save objects from function (PR#9365)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Wed 15 Nov 2006 - 15:07:19 GMT

dragan.sestovic@ubs.com writes:

> Full_Name: Dragan Sestovic
> Version: 2.3.0
> OS: Windows XP
> Submission from: (NULL) (139.149.1.194)
>
>
> I can not save R objects from function using "save". The simple example is
> below:
> I do not understand why function funSave.1 fails. Also, why does function
> funSave.2 work?
>
> > funSave.1 <- function(a)
> + {
> + save(a, file="a.1.dat")
> + }
> >
> > funSave.2 <- function(a)
> + {
> + b <- a
> + save(a, file="a.2.dat")
> + }
> >
> > a <- 1:10
> > a
> [1] 1 2 3 4 5 6 7 8 9 10
> > save(a, file="a.dat")
> > load("a.dat")
> > a
> [1] 1 2 3 4 5 6 7 8 9 10
> > a <- 1:10
> > funSave.1(a)
> > load("a.1.dat")
> > a
> Error: recursive default argument reference
> > a <- 1:10
> > funSave.2(b)
> > load("a.2.dat")
> > a
> [1] 1 2 3 4 5 6 7 8 9 10

.........
I cannot reproduce this in a current(!) R:

> funSave.1 <- function(a)

+ {
+   save(a, file="a.1.dat")
+ }

>
> funSave.2 <- function(a)
+ {
+   b <- a
+   save(a, file="a.2.dat")
+ }
>

> a <- 1:10
> a

 [1] 1 2 3 4 5 6 7 8 9 10
> save(a, file="a.dat")
> load("a.dat")
> a

 [1] 1 2 3 4 5 6 7 8 9 10
> a <- 1:10
> funSave.1(a)
> load("a.1.dat")
> a

 [1] 1 2 3 4 5 6 7 8 9 10
> a <- 1:10
> funSave.2(b)

Error in funSave.2(b) : object "b" not found
> load("a.2.dat")

Error in readChar(con, 5) : cannot open the connection In addition: Warning message:
cannot open compressed file 'a.2.dat'
> a

 [1] 1 2 3 4 5 6 7 8 9 10
> a <- 1:10
> funSave.2(a)
> load("a.2.dat")
> a

 [1] 1 2 3 4 5 6 7 8 9 10
-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Nov 16 12:14:00 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 16 Nov 2006 - 02:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.