An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110824/4131fa0c/attachment.pl>
debugging functions in R
7 messages · Eran Eidinger, Liviu Andronic, Justin Haynes +3 more
On Wed, Aug 24, 2011 at 4:20 PM, Eran Eidinger <eran at taykey.com> 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?
fortune('browser')
My solution when I run into mysteries like this is to put 'browser()' in the
function just before or after the line of interest. The magnitude and direction
of my stupidity usually become clear quickly.
-- Patrick Burns
R-help (February 2006)
Use browser() to inspect the environment and execute the code one step
at a time.
Liviu
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. 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. 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.
Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110824/bb553ff8/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110824/df3b9a39/attachment.pl>
Also check out the 'debug' package
On Wed, Aug 24, 2011 at 10:59 AM, Eran Eidinger <eran at taykey.com> wrote:
Wow, thanks Justin and Liviu, DebugOnce and browser. great! Eran On Wed, Aug 24, 2011 at 5:34 PM, Justin Haynes <jtor14 at gmail.com> wrote:
Another great tool is debugonce() wrap your function name in it and then execute your function call. debugonce(my.function) out<-my.function(df) And you'll be brought into the same interactive browser. (its Vi if im not mistaken which can take a little getting used to.) Justin On Wed, Aug 24, 2011 at 7:29 AM, Liviu Andronic <landronimirc at gmail.com>wrote:
On Wed, Aug 24, 2011 at 4:20 PM, Eran Eidinger <eran at taykey.com> 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?
fortune('browser')
My solution when I run into mysteries like this is to put 'browser()' in the function just before or after the line of interest. The magnitude and direction of my stupidity usually become clear quickly. ? -- Patrick Burns ? ? ?R-help (February 2006) Use browser() to inspect the environment and execute the code one step at a time. Liviu
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. 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. 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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail ______________________________________________ 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.
? ? ? ?[[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.
Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
1 day later
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.
See also the debug function, which allows you to walk through a
function line by line.
I also concur with Duncan's recommendation to try the R package
system. I'm an author of one of two contributed documents available
from CRAN -> Documentation: Contributed -> "Creating R Packages". When
I started writing R packages, I felt it tripled my software development
productivity overnight by making it easier to find bugs and keep track
of what I had done -- not to mention making it much easier to share my
work with others.
Hope this helps.
Spencer
On 8/25/2011 11:23 AM, Duncan Murdoch wrote:
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.
______________________________________________ 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.
Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San Jos?, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.com