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

Sven E. Templer sven.templer at gmail.com
Wed Oct 22 11:07:40 CEST 2014


He wants to prepend, not append.

On 22 October 2014 11:04, Henrik Bengtsson <hb at biostat.ucsf.edu> 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, "Sven E. Templer" <sven.templer at gmail.com> wrote:
>>
>> 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.
>>
>> Best, Sven.
>>
>> On 22 October 2014 02:32, YIHSU CHEN <yihsuc at gmail.com> wrote:
>> > 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:
>> >
>> > ampl.tab 2 1
>> > A  B
>> > 2   3
>> > 4   6
>> > 2   0
>> >
>> > Thanks for help.
>> >
>> > Yihsu
>> >
>> >         [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-help at 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.
>>
>> ______________________________________________
>> R-help at 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.



More information about the R-help mailing list