If the last line of an R script does not have a trailing newline, a small errror is produced at the end of the script. Small example. If file eg.r contains one line: getwd() and there is no newline after the closing paren $ R CMD BATCH eg.r produces an error: $ cat eg.r.Rout R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 Patched (2005-09-01), ISBN 3-900051-07-0 ...> getwd()proc.time()Error: syntax error Execution halted $ Is it worth changing the BATCH script so that it adds a newline before adding the call to proc.time()? Stephen
Martin Maechler
2005-Sep-01 11:39 UTC
[Rd] R CMD BATCH on scripts without trailing newline
>>>>> "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 $ aahh, now I finally understand via some people append those **ugly** unneeded ';' to the end of almost every 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()? Yes I think it would be. This is trivial, at least for <Rsrc>/src/scripts/BATCH Slightly better but more tricky: only append a newline "when needed". Any idea for that? You didn't tell us the *platform* you run R on (and BATCH does depend on the platform), but I know that it's a version of unix, Linux I suppose? BTW: The windows version of "R CMD BATCH" is actually *documented* do to work with files that don't end in newline. Martin