[R] on abort error, always show call stack?

2010-08-22 Thread ivo welch
Dear R Wizards---is it possible to get R to show its current call
stack (sys.calls()) upon an error abort?  I don't use ESS for
execution, and it is often not obvious how to locate how I triggered
an error in an R internal function.  Seeing the call stack would make
this easier.  (right now, I sprinkle cat statements everywhere, just
to locate the line where the error appears.)  Of course, I would
really love to see the line in my program that triggered this, but I
have asked this before, and I understand this is too difficult to get
into the R language.

regards,

/iaw


Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] on abort error, always show call stack?

2010-08-22 Thread Matt Shotwell
On Sun, 2010-08-22 at 11:41 -0400, ivo welch wrote:
 Dear R Wizards---is it possible to get R to show its current call
 stack (sys.calls()) upon an error abort?  I don't use ESS for
 execution, and it is often not obvious how to locate how I triggered
 an error in an R internal function.  Seeing the call stack would make
 this easier.  (right now, I sprinkle cat statements everywhere, just
 to locate the line where the error appears.)  Of course, I would
 really love to see the line in my program that triggered this, but I
 have asked this before, and I understand this is too difficult to get
 into the R language.

The traceback() function will print out the call stack after an error.
However, you may find the debug() family of functions more useful for
debugging. Also see the browser() function.

-Matt

 
 regards,
 
 /iaw
 
 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Matthew S. Shotwell
Graduate Student 
Division of Biostatistics and Epidemiology
Medical University of South Carolina

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] on abort error, always show call stack?

2010-08-22 Thread Charles C. Berry

On Sun, 22 Aug 2010, Matt Shotwell wrote:


On Sun, 2010-08-22 at 11:41 -0400, ivo welch wrote:

Dear R Wizards---is it possible to get R to show its current call
stack (sys.calls()) upon an error abort?  I don't use ESS for
execution, and it is often not obvious how to locate how I triggered
an error in an R internal function.  Seeing the call stack would make
this easier.  (right now, I sprinkle cat statements everywhere, just
to locate the line where the error appears.)  Of course, I would
really love to see the line in my program that triggered this, but I
have asked this before, and I understand this is too difficult to get
into the R language.


The traceback() function will print out the call stack after an error.
However, you may find the debug() family of functions more useful for
debugging. Also see the browser() function.



Further, you might set

options( error = recover )

which prints the list of current calls, and prompts the user to select 
one of them. And then allows browser()-ing.


Chuck




-Matt



regards,

/iaw


Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


--
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] on abort error, always show call stack?

2010-08-22 Thread ivo welch
yes, thank you.  is it possible to have it invoked to STDERR
automatically on a program abort?

/iaw

On Sun, Aug 22, 2010 at 11:50 AM, Matt Shotwell shotw...@musc.edu wrote:
 On Sun, 2010-08-22 at 11:41 -0400, ivo welch wrote:
 Dear R Wizards---is it possible to get R to show its current call
 stack (sys.calls()) upon an error abort?  I don't use ESS for
 execution, and it is often not obvious how to locate how I triggered
 an error in an R internal function.  Seeing the call stack would make
 this easier.  (right now, I sprinkle cat statements everywhere, just
 to locate the line where the error appears.)  Of course, I would
 really love to see the line in my program that triggered this, but I
 have asked this before, and I understand this is too difficult to get
 into the R language.

 The traceback() function will print out the call stack after an error.
 However, you may find the debug() family of functions more useful for
 debugging. Also see the browser() function.

 -Matt


 regards,

 /iaw

 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

 --
 Matthew S. Shotwell
 Graduate Student
 Division of Biostatistics and Epidemiology
 Medical University of South Carolina



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] on abort error, always show call stack?

2010-08-22 Thread Matt Shotwell
How about this:

test - function(x) log(x)
tryCatch({
#Code that will error
test(a)
}, finally = {
sink(stderr())
traceback()
sink()
})


If you are running non-interactively, invoke R with the --interactive
flag to force it. Saving the code above to test.R, you can see the
effect with

$ R --interactive  test.R 1 test.out 2 test.err

This seems reasonable, but maybe others will say if I'm missing
something more automagic.

-Matt


On Sun, 2010-08-22 at 11:58 -0400, ivo welch wrote:
 yes, thank you.  is it possible to have it invoked to STDERR
 automatically on a program abort?
 
 /iaw
 
 On Sun, Aug 22, 2010 at 11:50 AM, Matt Shotwell shotw...@musc.edu wrote:
  On Sun, 2010-08-22 at 11:41 -0400, ivo welch wrote:
  Dear R Wizards---is it possible to get R to show its current call
  stack (sys.calls()) upon an error abort?  I don't use ESS for
  execution, and it is often not obvious how to locate how I triggered
  an error in an R internal function.  Seeing the call stack would make
  this easier.  (right now, I sprinkle cat statements everywhere, just
  to locate the line where the error appears.)  Of course, I would
  really love to see the line in my program that triggered this, but I
  have asked this before, and I understand this is too difficult to get
  into the R language.
 
  The traceback() function will print out the call stack after an error.
  However, you may find the debug() family of functions more useful for
  debugging. Also see the browser() function.
 
  -Matt
 
 
  regards,
 
  /iaw
 
  
  Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
  --
  Matthew S. Shotwell
  Graduate Student
  Division of Biostatistics and Epidemiology
  Medical University of South Carolina
 
 

-- 
Matthew S. Shotwell
Graduate Student 
Division of Biostatistics and Epidemiology
Medical University of South Carolina

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] on abort error, always show call stack?

2010-08-22 Thread Henrik Bengtsson
For what's it worth, the Exception class of R.oo extends the
simpleError class.  When an Exception object is instantiated it also
records the stack trace (traceback()).  Then when the exception is
thrown it will behave just as stop().  For the convenience,
throw(message) does all this in one go, cf. stop().  You can use
throw() wherever you use stop(). Then, when an Exception object is
print():ed, it also displays the traceback.

Example:

 library(R.oo);
Loading required package: R.methodsS3
R.methodsS3 v1.2.0 (2010-03-13) successfully loaded. See ?R.methodsS3 for help.
R.oo v1.7.3 (2010-06-04) successfully loaded. See ?R.oo for help.

 bar - function() throw(Woops!)
 foo - function() bar()
 foo()
Error in list(`foo()` = environment, `bar()` = environment, `throw(Woops!)
` = environment,  :

[2010-08-22 11:05:09] Exception: Woops!
  at throw(Exception(...))
  at throw.default(Woops!)
  at throw(Woops!)
  at bar()
  at foo()

The neat thing with always getting the traceback is that almost always
people will cut'n'paste it when report errors/asking questions, which
avoids standard replied asking for Please rerun and when you get the
error write traceback() and report back..  I haven't done it yet, but
you imagine adding an global option() where the sessionInfo() is also
printed, an additional message referring to webpage etc.

/Henrik

On Sun, Aug 22, 2010 at 8:41 AM, ivo welch ivo.we...@gmail.com wrote:
 Dear R Wizards---is it possible to get R to show its current call
 stack (sys.calls()) upon an error abort?  I don't use ESS for
 execution, and it is often not obvious how to locate how I triggered
 an error in an R internal function.  Seeing the call stack would make
 this easier.  (right now, I sprinkle cat statements everywhere, just
 to locate the line where the error appears.)  Of course, I would
 really love to see the line in my program that triggered this, but I
 have asked this before, and I understand this is too difficult to get
 into the R language.

 regards,

 /iaw

 
 Ivo Welch (ivo.we...@brown.edu, ivo.we...@gmail.com)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.