Re: [R] add text to the first line of an output file

2014-10-22 Thread Henrik Bengtsson
Alright, if it is the case that the "output file" already exists, then yes Sven's suggestion is more or less the only solution. Henrik On Oct 22, 2014 2:08 AM, "Sven E. Templer" wrote: > He wants to prepend, not append. > > On 22 October 2014 11:04, Henrik Bengtsson wrote: > > You can! Open a f

Re: [R] add text to the first line of an output file

2014-10-22 Thread Sven E. Templer
He wants to prepend, not append. On 22 October 2014 11:04, Henrik Bengtsson wrote: > You can! Open a file connection and write to that. Whatever write commands > you use will append to the output. Don't forget to close the connection at > the end. See ?file > > Henrik > > On Oct 22, 2014 12:33 AM

Re: [R] add text to the first line of an output file

2014-10-22 Thread Henrik Bengtsson
You can! Open a file connection and write to that. Whatever write commands you use will append to the output. Don't forget to close the connection at the end. See ?file Henrik On Oct 22, 2014 12:33 AM, "Sven E. Templer" wrote: > Hi. > > You can't. > > But using a second file where you first writ

Re: [R] add text to the first line of an output file

2014-10-22 Thread Rui Barradas
Hello, Just use ?cat and ?write.table with append = TRUE. Something like the following. txt <- "ampl.tab 2 1" dat <- read.table(text = " A B 2 3 4 6 2 0 ", header = TRUE) tmp <- "tmp.txt" cat(txt, "\n", file = tmp) " Don't forget the newline "\n" write.table(dat, file = tmp, append = T

Re: [R] add text to the first line of an output file

2014-10-22 Thread Sven E. Templer
Hi. You can't. But using a second file where you first write your header and then append the original file is a solution. ?cat and ?write.table with a focus on the 'append' argument should help. you can then use ?unlink to delete the original file and ?file.rename to rename the second, if desired

[R] add text to the first line of an output file

2014-10-21 Thread YIHSU CHEN
Hi guys; I want to write some text at the first line of an output file. The output file will be used for other software. In particular, the following text "ampl.tab 2 1" needs to be added to the first line of an df output file. As a hypothetic example, the output in text file should be like: a