[R] How to save a data set as .txt on fly?

Stephen Liu satimis at yahoo.com
Fri Nov 26 06:23:17 CET 2010


Hi David,


> But you didn't try:

> DNase    # which was after all the name of the object you saved.

Sorry I don't follow.


I can't do it with following steps:
> DNase
> save(DNase, file="C:/Users/satimis/Documents/dnase.txt")
> load(file="C:/Users/satimis/Documents/dnase.txt")
> dnase
Error: object 'dnase' not found
> dnase.txt
Error: object 'dnase.txt' not found


sink command can make it

> sink("dnase.txt", append=TRUE, split=TRUE)
> DNase
> sink()

to load the file
> read.table(file="C:/Users/satimis/Documents/dnase.txt")

Besides the file created can be read with Notpad and WordPad


> Does the above "method" (typing the name of the save object rather  
> than the file name) meet your definition of "on the fly"?
Could you pls explain in more detail?  Thanks


> Right. Try reading the Posting Guide which among many other useful  
> things has a method for saving objects in text format.

Yes.

I'm curious to know why the .txt file created in this way can't be read with 
Notpad and WordPad?


B.R.
Stephen L




----- Original Message ----
From: David Winsemius <dwinsemius at comcast.net>
To: Stephen Liu <satimis at yahoo.com>
Cc: r-help at r-project.org
Sent: Fri, November 26, 2010 11:56:23 AM
Subject: Re: [R] How to save a data set as .txt on fly?


On Nov 25, 2010, at 10:45 PM, Stephen Liu wrote:

> Hi folks,
>
> Win7 64bit
>
> I tried to save DNase, a data set on database, as .txt file for  
> future use with
> load.
>
> I can't do it on fly;
>> save(DNase, file="C:/Users/satimis/Documents/aaa.txt")
>> load(file="C:/Users/satimis/Documents/aaa.txt")
>> aaa
> Error: object 'aaa' not found
>> aaa.txt
> Error: object 'aaa.txt' not found

But you didn't try:

DNase    # which was after all the name of the object you saved.
>
>
> I must perform following steps;
>> aaa<-DNase
>> save(aaa, file="C:/Users/satimis/Documents/aaa.txt")
>> load(file="C:/Users/satimis/Documents/aaa.txt")
>
>> aaa
>    Run        conc density
> 1     1  0.04882812   0.017
> 2     1  0.04882812   0.018
> 3     1  0.19531250   0.121
> ....
>
>
> Is there any way doing it on fly?

Does the above "method" (typing the name of the save object rather  
than the file name) meet your definition of "on the fly"?
>
> Besides aaa.txt can't be read direct with Notepad nor WordPad

Right. Try reading the Posting Guide which among many other useful  
things has a method for saving objects in text format.

>
> TIA
>
> B.R.
> Stephen L
>
>
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT





More information about the R-help mailing list