[R] write.table with append=T after using cat on same file

William Dunlap wdunlap at tibco.com
Mon Jul 27 22:50:39 CEST 2015


This will happen if you have redefined 'T':
  > T <- 101:104
  > write.table(df, file="junk.txt", sep=",", append=T, quote=F,
row.names=F, col.names=F)
  Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument
Use 'TRUE' and 'FALSE' instead of 'T' and 'F' this sort of problem.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Mon, Jul 27, 2015 at 1:32 PM, Waichler, Scott R <Scott.Waichler at pnnl.gov>
wrote:

> Hi,
>
> For years I've been writing text to the beginning of files with
> cat(append=F) , then following that text with data written by
> write.table(append=T).  It is now giving me an error message.  I'm using
> R-3.1.2.  What gives?
>
> df <- data.frame(x = 1, y = 1:10, z = 10:1)
> cat(file="junk.txt", sep="", "# An introductory note.\n")
> write.table(df, file="junk.txt", sep=",", append=T, quote=F, row.names=F,
> col.names=F)
>
> Error in file(file, ifelse(append, "a", "w")) : invalid 'open' argument
>
> Thanks,
> Scott Waichler
> Pacific Northwest National Laboratory
> Richland, WA  USA
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list