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.
Duncan Murdoch