[R] R debugging options

Duncan Murdoch murdoch at stats.uwo.ca
Tue Apr 18 03:16:27 CEST 2006

On 4/17/2006 7:45 PM, Larry Howe wrote:
> Hello,
> What options are available for me to debug my R scripts? For example I 
> normally do something like
>> source("myfunctions.R")
>> function1("height", "weight")
> myfunctions.R is a large R source file that contains many functions. function1 
> is the "main" function in myfunctions.R. It calls many other user-written 
> functions that are also in myfunctions.R.
> I only want to debug the R scripts. I do not need to get into the code of R 
> itself. I would like to be able to:
> - see the source as I am debugging
> - execute line-by-line
> - see and modify variables
> - have the option to either descend into function calls, or not
> - have the option to either descend into loops, or not
> Maybe this is asking too much but I thought I would lay out my dreams and then 
> you can tell me what is really possible.

You can do some of that using the debug() and browser() functions.  They 
aren't exactly source-level debuggers:  they work by showing you 
deparsed versions of the code.

Since these aren't source oriented, you don't have the usual "descend" 
option.  You set a flag on a function, and enter the debugger whenever 
that function is called.

Mark Bravington's debug package goes a bit further towards a true 
source-level debugger.

The soon-to-be-released 2.3.0 has information on debugging in the R 
Extensions manual.  I don't think it's online yet other than as part of 
the beta versions.  You can also see some mainly Windows oriented 
material on my web page, 

Duncan Murdoch

More information about the R-help mailing list