[R] debugging functions in R

Duncan Murdoch murdoch.duncan at gmail.com
Thu Aug 25 20:23:05 CEST 2011


On 11-08-24 10:20 AM, Eran Eidinger wrote:
> Hi,
>
> I am not sure if this is the right list to ask this question (though I did
> not find a more appropriate one).
> I've started using R a month ago, and small scripts work fine. However, when
> I start writing more complex code, it gets messy.
>
> 1. Is there any way to debug "normally", with breakpoints?

The trace() function does that.  setBreakpoint() is a front end for it. 
  One current limitation is that it only allows one breakpoint per 
function; that may change soon.

> 2. I am using the Eclipse plugin (StatET), and tried JGR(). Is there an IDE
> that enables breakpoints?
> 3. Is there an equivalent to "include" in other programming languages? So
> many functions in one file are very messy. I would like to break it to
> several files.

Write a package.  It is much easier than it looks at first.  Start with 
package.skeleton, and follow the instructions from there.

> 4. Any way to create a "local" context of variables inside a function?
> Otherwise I have to be careful to give different names inside functions, to
> those in the workspace.

Functions always have a local context for writing.  There's no simple 
way to create a local context for reading.

Duncan Murdoch

>
> I should point that I am a long time Matlab user and am probably expecting
> some things that don't necessarily exist in R...
>
> I know it's a lot, if there is a more appropriate forum to ask these, please
> point me in that direction.
>
> Thanks,
> Eran.
>
> *
>
> *
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list