[R] difference between script and a function....

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Sat Dec 24 16:57:45 CET 2022


On Sat, 24 Dec 2022 15:47:14 +0000
akshay kulkarni <akshay_e4 using hotmail.com> wrote:

> How do you debug if there is an error, particularly if I run the
> script from the BASH prompt? 

Post-mortem debugging for non-interactive R scripts can be enabled by
setting options(error = quote(dump.frames("A_SUITABLE_FILE_NAME",
to.file = TRUE))) in your script. See ?dump.frames for more information.

When you're running command-line R interactively, the main tools at
your disposal are traceback() and browser() (see their respective help
pages). There are two main ways to use the browser: (1) by setting the
debugging flag on a function via debug(function) or debugonce(function)
-- you will land in the browser when the function is called -- and (2)
by setting options(error = recover), which will launch the browser at
the time of the crash, letting you walk the stack and inspect the
values of various variables.

For more information on pure-R debugging, see The R Inferno book:
<https://www.burns-stat.com/documents/books/the-r-inferno/>

-- 
Best regards,
Ivan



More information about the R-help mailing list