[R] export to text file

Spencer Graves spencer.graves at pdf.com
Mon Feb 21 18:55:16 CET 2005


       1.  Did you work the example at the end of the "write.table" help 
file?  In R 2.0.1, this is:

   write.table(x, file = "foo.csv", sep = ",", col.names = NA)

	  This should create a file "foo.csv" in the working directory.  To 
find the working directory, use "getwd()";  to set it, use "setwd(...)". 
  When you do this, can you find "foo.csv"?

       2.  I tried the command in your email:

	  >write.table(temp.data.data, file = "c:\Current Work")

	  I got a file "Current Work" (with no *.txt or other extension) in 
"C:\".

	  3.  You need to be careful with "\" in text strings, because it is an 
R escape character.  For example, the following modification of your 
example produced an error:

 > write.table(temp.data.data, file = "c:\the Work")
Error in file(file, ifelse(append, "a", "w")) :
	unable to open connection
In addition: Warning message:
cannot open file `c:	he Work'

	  This occurs because "\t" is a tab character.

	  4.  If you wanted a file called, say, "temp.data.data.txt" in 
"c:\Current Work", you need something like the following:

write.table(temp.data.data,
   file = "c:\\Current Work\\temp.data.data.txt")	

	  Since "\" is the escape character in R, to get "\" retained in the 
character string, you need to use "\\";  "/" is accepted as a substitute 
for "\\".

	  hope this helps.
	  spencer graves

Christina D Smith wrote:

 >I'm not sure.  The following code gives me no errors:
 >write.table(temp.data.data, file = "c:\Current Work")
 >Yet no new file is created.
 >Christy
 >
 >Quoting Spencer Graves <spencer.graves at pdf.com>:
 >

###################
      Did you try "write.table"?  If yes, what do you see as its
deficiencies?

      spencer graves

Christina D Smith wrote:

>I'm trying to export a large data frame to a text file for permanent
>storage.  The only thing I could find was the treeglia Package but that
>didn't work.  Any suggestions?
>Thanks!
>
>Christina D Smith
>PhD Student, GRA
>Statistics Department
>Kansas State University
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>  
>




More information about the R-help mailing list