[R] how to save object created by assign()

Jinsong Zhao jszhao at yeah.net
Sat Nov 20 02:19:21 CET 2010


On 2010-11-19 22:37, Jinsong Zhao wrote:
> Hi there,
>
> When I run the following code, I could get correct objects (with correct
> values):
>
> for(i in 1:6) { #-- Create objects 'r.1', 'r.2', ... 'r.6' --
> nam <- paste("r",i, sep=".")
> assign(nam, 1:i)
> # save(nam, file = paste(nam, "RData", sep = "."))
> }
>
> I hope to save the object 'r.1', 'r.2', ..., 'r.6' using the above
> commented line, however, I just got 'r.1.RData' with a object 'nam' in
> it, which had the value, e.g., 'r.6', not the value of 'r.6', i.e., 1:6.
>
> Any suggestions? Thanks in advance.
>
> Jinsong
>

sorry for the noise. problem solved. just change the

save(nam, file = paste(nam, "RData", sep = "."))
to
save(list = nam, file = paste(nam, "RData", sep = "."))

Regards,
Jinsong



More information about the R-help mailing list