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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sun 07 Nov 2004 - 01:53:52 EST


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
> > NAMESPACE).
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 vi.)

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

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sun Nov 07 01:59:55 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:01:07 EST