[Rd] wishlist: better error message in R CMD check

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Nov 6 15:53:52 CET 2004

On Sat, 6 Nov 2004, Uwe Ligges wrote:

> Liaw, Andy wrote:
> > Gabor,
> > 
> > I guess is that you did not try to run R CMD INSTALL before R CMD check.  R
> > CMD check will try to install the package first (in pkg.Rcheck), and only if
> > that's successful would checks be done.
> > 
> > The installation process will concatenate all R files in R/ to a single file
> > and essentially source() that in upon package loading.  That's where you
> > would see the syntax error.  I believe the recommended way is to install the
> > package and play with that a bit first, before doing R CMD check.  You'd
> > find some problems are much easier to find that way (e.g., errors in

Indeed, that is the advice: you often get much more informative error 
messages that R CMD check hides.  To be explicit, install and then load 
the package and check its basic functionality before R CMD check.

However, if you get a syntax error it is either in the NAMESPACE file or 
one of the *.R files, and sourcing all of them will rapidly find which.

> >>From: Gabor Grothendieck
> >>
> >>I was running R CMD check on Windows XP 2.0.1beta and 
> >>got this:
> >>
> >>Error in parse(file, n, text, prompt) : syntax error on 602
> >
> I found that syntax errors quite frequently are caused by missing 
> newlines at the end of files.
> What about changing the build scipts so that a newline is inserted after 
> each of those files?

Time to get a better editor, Uwe!  Those I use do not allow you to
save a .R file without a final NL.  (I would have thought you would have 
learned not to leave an incomplete last line after being bitten a few 
times.  In Emacs, set `Require Final Newline', and it's the default in 

However, this is not done by the `build scipts' (or even scripts) but
by tools:::.install_package_code_files() at

    if(!all(file.append(outFile, codeFiles)))
        stop("unable to write code files")

So that is the place to alter this.  There would be a small overhead both
at INSTALL time and load time (but the latter only for packages which are
not save-imaged or lazy-loaded), I suspect a negligible one.  In any case
file.append could be written more efficiently for this case (outFile is
opened for each of the codeFiles) with making sure each file ended in LF
made an option.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list