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.

______________________________________________
R-help@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.

Reply via email to