Re: [R] line numbers and file names in error messages

From: Jan T. Kim <jtk_at_cmp.uea.ac.uk>
Date: Sat 16 Apr 2005 - 03:15:49 EST

On Fri, Apr 15, 2005 at 11:27:13AM -0400, Gabor Grothendieck wrote:
> On 4/15/05, Vivek Rao <rvivekrao@yahoo.com> wrote:
> > Many of my R scripts call other R scripts using the
> > source function. If there is a syntax error in one of
> > the scripts, I get an error message such as
> >
> > Error in parse(file, n, text, prompt) : syntax error
> > on line 1
> >
> > but the name of the file where the error occurs is not
> > given. Other error messages such as
> >
> > Error in print(xxx) : Object "xxx" not found
> >
> > show neither the file name or the line number. Is
> > there a way to get this information in error messages?
> > I have found it helpful in other programming
> > languages.
>
> Perhaps at the end of each script you could add a print statement
> to tell you it had successfully finished.

No, this won't help. The trouble is that the first type of error is detected during parsing while the second type of error occurs during execution. For the parser, the line

    print(xxx);

is perfectly fine, the error is that the thing to be printed does not exist. At the time of execution, the information about which line in what file contained the code that caused the problem.

The traceback() function can be useful for investigating execution time errors.

Best regards, Jan

-- 
 +- Jan T. Kim -------------------------------------------------------+
 |    *NEW*    email: jtk@cmp.uea.ac.uk                               |
 |    *NEW*    WWW:   http://www.cmp.uea.ac.uk/people/jtk             |
 *-----=<  hierarchical systems are for files, not for humans  >=-----*

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Apr 16 02:26:33 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:11 EST