[Rd] R CMD BATCH on scripts without trailing newline
Martin Maechler
maechler at stat.math.ethz.ch
Sat Sep 3 13:56:03 CEST 2005
>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch>
>>>>> on Thu, 1 Sep 2005 13:39:52 +0200 writes:
>>>>> "StEgl" == Stephen Eglen <S.J.Eglen at damtp.cam.ac.uk>
>>>>> on Thu, 1 Sep 2005 12:09:15 +0100 writes:
StEgl> If the last line of an R script does not have a
StEgl> trailing newline, a small errror is produced at the
StEgl> end of the script.
StEgl> Small example. If file eg.r contains one line:
StEgl> getwd() and there is no newline after the closing
StEgl> paren
StEgl> $ R CMD BATCH eg.r
StEgl> produces an error: $ cat eg.r.Rout
StEgl> R : Copyright 2005, The R Foundation for Statistical
StEgl> Computing Version 2.1.1 Patched (2005-09-01), ISBN
StEgl> 3-900051-07-0
StEgl> ...
>>> getwd()proc.time()
StEgl> Error: syntax error Execution halted $
MM> aahh, now I finally understand via some people append
MM> those **ugly** unneeded ';' to the end of almost every
MM> line of R code. It would have helped here :-) :-)
StEgl> Is it worth changing the BATCH script so that it adds
StEgl> a newline before adding the call to proc.time()?
MM> Yes I think it would be. This is trivial, at least for
MM> <Rsrc>/src/scripts/BATCH Slightly better but more
MM> tricky: only append a newline "when needed". Any idea
MM> for that?
It's probably not worth the extra effort (I agree with Jan on
*that); I've added the obvious to the BATCH script used on
unix-alike platforms, now adding a newline before 'proc.time()'
unconditionally. I hope people can live with an extra byte in
the output files.
Martin
> BTW: The windows version of "R CMD BATCH" is actually
MM> *documented* do to work with files that don't end in
MM> newline.
More information about the R-devel
mailing list