[R] writing multiple lines to a file

arun smartpink111 at yahoo.com
Wed Jul 17 04:53:31 CEST 2013


HI,
May be this helps:
printer1<- file("out1.txt","w")
write(sprintf("This is line %d.\n",1),printer1,append=TRUE) 
write("This is line 2",printer1,append=TRUE)
close(printer1)

#or


 printer1<- file("out1.txt","w")
writeLines("This is line",con=printer1,sep="\n")
writeLines("This is line 2",con=printer1)
 close(printer1)
A.K.


Hello, I am trying to wrote multiple lines to a file, but I only seem to be able to write the last line. 

printer = file("out.txt") 
write(sprintf("This is line %d.\n",1),printer,append=T) 
write("This is line 2.",printer,append=T) 
close(printer) 

How can I fix this? I would like to be able to do this in a for-loop with hundreds of elements.



More information about the R-help mailing list