[R] write a bunch of objects to files
Thomas Lumley
tlumley at u.washington.edu
Tue Oct 30 00:26:40 CET 2001
On Mon, 29 Oct 2001, David White wrote:
>
> Hello all,
>
> I've got a bunch of objects I'd like to write to .csv files. For example,
> I have objects conveniently called
>
> n002.csv
> n001.csv
> p103.csv
> .
> .
> .
>
> I tried a loop:
>
> > for(i in ls(pattern="csv"))
> +write.table(i, file=i, sep=",", quote=F)
>
> That, of course, wrote out a bunch of files that contained
>
> x
> 1, n002.csv
>
> Or the like.
>
> How can I get i in the loop above to be an object instead of a string?
>
Use substitute():
for(i in ls(pattern="csv"))
eval(substitute(obj, file=fname, sep=",", quote=F),
list(obj=as.name(i),fname=i)
)
or get():
for(i in ls(pattern="csv"))
write.table(get(i), file=i, sep=",", quote=F)
-thomas
Thomas Lumley Asst. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list