[R] append lines to a created file

Rolf Turner r.turner at auckland.ac.nz
Wed Dec 17 02:15:35 CET 2008


On 17/12/2008, at 1:43 PM, Jörg Groß wrote:

> hi,
>
> I try to append a line to a file with;
>
> writeLines("xxx", con = "file.txt, sep = "\n")
>
>
> but it always overwrites the existing content.
>
>
> How can I "change" the "mode" of writeLines to append ("a") ?

The help on connections says:

	In general functions using connections will open them if they are not
	open, but then close them again, so to leave a connection open call  
open explicitly.

So do something like:

	zz <- file("file.txt","w")
	writeLines("xxx",con=zz,sep="\n")
	writeLines("A load of dingos' kidneys.",con=zz,sep="\n")
	
	etc.
	etc.

	close(zz)

But why not just use sink() and cat()?  Much simpler, IMHO.

	cheers,

		Rolf Turner
######################################################################
Attention: 
This e-mail message is privileged and confidential. If you are not the 
intended recipient please delete the message and notify the sender. 
Any views or opinions presented are solely those of the author.

This e-mail has been scanned and cleared by MailMarshal 
www.marshalsoftware.com
######################################################################



More information about the R-help mailing list