Skip to content
Prev 67791 / 398502 Next

line numbers and file names in error messages

On Fri, Apr 15, 2005 at 12:37:46PM -0400, Gabor Grothendieck wrote:
Sorry if I sounded a bit harsh here. What I meant is that the printing
approach may be misleading. Consider:

    # file1.r
    foo <- function()
    {
      print(xxx);
    }
    print("file1: success");

    # file2.r
    source("file1.r");
    bar <- function()
    {
      foo();
    }
    bar();
    xxx <- "hello, world";
    print(xxx);
    print("file2: success");

    > source("file2.r");
    [1] "file1: success"
    Error in print(xxx) : Object "xxx" not found

Now, the unsuspecting may easily be misled to believe that print(xxx) in
file2.r is at fault, whereas the traceback reveals that the foo function
is the culprit:

    > traceback()
    6: print(xxx)
    5: foo()
    4: bar()
    3: eval.with.vis(expr, envir, enclos)
    2: eval.with.vis(ei, envir)
    1: source("file2.r")

Best regards, Jan