Skip to content
Prev 10153 / 398503 Next

supressing linefeed at end of file

Hello,

I want to do simulations with an external simulation model. For this
purpose I wrote a R-script which makes the pre- and post-processing of
the data (generate scenarios, analyze results).

The R-script writes the input file for the simulation with e.g. 

write(x, file="test.dat", ncolumns=10)

The problem is, however, that this command (and even constructions with
cat) will add a linefeed after the last line of data. Unfortunately the
simulation program however is very stupid, as it does not allow a
linefeed after the last line. It interprets the linefeed after the last
line of data as an empty line and will fail.

I did not find anything concerning this problem in the R-data.pdf
manual. A first solution was to use grep to eliminate the empty line,
but the R-script should run not only on linux, but also on windows
machines without cygwin, perl or similar. Is there a simple "R only"
solution? Otherwise I should write a special C program.

Thanks in advance!

Thomas Petzoldt