[Rd] R CMD BATCH on scripts without trailing newline

Martin Maechler maechler at stat.math.ethz.ch
Thu Sep 1 13:39:52 CEST 2005


>>>>> "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



More information about the R-devel mailing list