From ggrothendieck at gmail.com  Sat Oct 21 05:11:15 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 20 Oct 2006 23:11:15 -0400
Subject: [Rd] parse/INSTALL feature request(s)
In-Reply-To: <45398188.4000709@stats.uwo.ca>
References: <45396A81.8080808@sfu.ca> <45398188.4000709@stats.uwo.ca>
Message-ID: <971536df0610202011u25f8ccfnba45dc9cc07f39d1@mail.gmail.com>

On 10/20/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 10/20/2006 8:32 PM, Michael Toews wrote:
> > Hi,
> > I have a feature request for 'parse', and possibly the 'R CMD INSTALL'
> > command to display more informative error information. Specifically,
> > after making several modifications to a package on my system (the
> > package name is irrelevant; I'm using R 2.3.1 on Debian):
> > $ R CMD INSTALL seas
> > * Installing *source* package 'seas' ...
> > ** R
> > ** data
> > ** inst
> > ** preparing package for lazy loading
> > Error in parse(file, n, text, prompt) : syntax error at
> > 1222:       ylim <-
> > 1223:     else
> > Execution halted
> > ERROR: lazy loading failed for package 'seas'
> > ** Removing '/usr/local/lib/R/site-library/seas'
> >
> > Of the 24 or so *.R source files in the edited package, I'm not sure
> > where I had made the syntax error, but it would be very nice to see an
> > error message that says something more helpful, such as "Error in
> > parse(file, n, text, prompt) : syntax error in function 'foo' at ...".
>
> Yes, that would be nice, but I don't think it's possible:  if the parse
> fails, R won't know enough to know that it was in the middle of parsing
> function 'foo'.
>
> What would be possible is to do like other preprocessors do, and put
> comments into the source file to indicate the origin of each line:  then
> the parser could tell you the location in the original file, which would
> be a lot more useful.  This would slow things down a bit and make the
> package bigger so we'd probably want it to be optional, but it would
> help a lot in situations like yours.
>
> > Is it possible for 'parse' to display the parent function name in which
> > the error occurred? As for 'R CMD INSTALL' goes, I realize that all the
> > *.R files are cat'ed together, then parsed as one file, so it is
> > difficult report a file name and line number(s). Is this concatenating
> > necessary? Or couldn't the individual files be parsed (and errors/line
> > #'s reported for offending files), then combined in an environment for
> > the INSTALL'ed package?
>
> I don't know the reason for putting them in one file.
>
> > In the mean time, my solution to find the offending file is:
> > for(i in dir(pattern=".R$")){
> >     print(i)
> >     parse(i)
> > }
>
> That looks like a good idea; if it doesn't catch the error, then it's
> probably something wrong with the last line in one of the files, e.g.
> not having a newline at the end of it.
>

I try to develop my functions one at a time for this very reason.  Of course
its not always feasible but if you can do it followed by an install each time
it makes it easier to locate problems.




[Rd] parse/INSTALL feature request(s)
Gabor Grothendieck