An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/705828e4/attachment.pl>
How do I step thru all lines (including step into sub-routines) in a R script?
11 messages · Duncan Murdoch, William Dunlap, Michael
On 12-11-13 4:05 PM, Michael wrote:
How do I step thru all lines (including step into sub-routines) in a R script? Hi all, I know I can put a "browser()" into any place... but how to step into sub-routines? Keep pressing "n" at the break-point seems not getting me into the sub-routines?
Mark all your functions for debugging using debug(). It's not like a debugger that will single step until you tell it to just continue on, but it gives you the individual steps. When you've had enough of that, use undebug() to mark the functions for stepping over. Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/e2d844f5/attachment.pl>
On 12-11-13 4:50 PM, Michael wrote:
but there are hundreds of such functions...? how to mark them all using "debug"?
When you see you are about to enter one that you haven't marked, you can mark it from within the debugger. (So in some other debuggers you'd type "s" to step in; in R you need to type "debug(foo)" then "n". Duncan Murdoch
thanks!
On Tue, Nov 13, 2012 at 3:43 PM, Duncan Murdoch
<murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>> wrote:
On 12-11-13 4:05 PM, Michael wrote:
How do I step thru all lines (including step into sub-routines)
in a R
script?
Hi all,
I know I can put a "browser()" into any place...
but how to step into sub-routines?
Keep pressing "n" at the break-point seems not getting me into the
sub-routines?
Mark all your functions for debugging using debug(). It's not like
a debugger that will single step until you tell it to just continue
on, but it gives you the individual steps.
When you've had enough of that, use undebug() to mark the functions
for stepping over.
Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/ab8eab68/attachment.pl>
On 12-11-13 5:07 PM, Michael wrote:
Is there a way to strip out all functions in hundreds of R script? And then I can create a script which does "debug(foo1); debug(foo2); debug(foo3);",etc?
Not a simple one. You could try parsing all the scripts, and look for function definitions, and then see where those were assigned. It would be easier to organize your scripts so that some of them define functions, and others call them. Then just define all the functions, and use ls() to find their names. Duncan Murdoch
Thank you!
On Tue, Nov 13, 2012 at 3:56 PM, Duncan Murdoch
<murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>> wrote:
On 12-11-13 4:50 PM, Michael wrote:
but there are hundreds of such functions...? how to mark them
all using
"debug"?
When you see you are about to enter one that you haven't marked, you
can mark it from within the debugger. (So in some other debuggers
you'd type "s" to step in; in R you need to type "debug(foo)" then "n".
Duncan Murdoch
thanks!
On Tue, Nov 13, 2012 at 3:43 PM, Duncan Murdoch
<murdoch.duncan at gmail.com <mailto:murdoch.duncan at gmail.com>
<mailto:murdoch.duncan at gmail.__com
<mailto:murdoch.duncan at gmail.com>>> wrote:
On 12-11-13 4:05 PM, Michael wrote:
How do I step thru all lines (including step into
sub-routines)
in a R
script?
Hi all,
I know I can put a "browser()" into any place...
but how to step into sub-routines?
Keep pressing "n" at the break-point seems not getting
me into the
sub-routines?
Mark all your functions for debugging using debug(). It's
not like
a debugger that will single step until you tell it to just
continue
on, but it gives you the individual steps.
When you've had enough of that, use undebug() to mark the
functions
for stepping over.
Duncan Murdoch
You can make a list of the names of the functions defined at the top
level in a script using the following.
namesOfFunctionsDefined <- function (expr) { # expr is typically output of parse(file)
expr <- as.list(expr)
isFunctionAssignment <- function(expr) is.call(expr) && identical(expr[[1]],
as.name("<-")) && is.call(expr[[3]]) && identical(expr[[3]][[1]],
as.name("function"))
asgns <- vapply(expr, isFunctionAssignment, FALSE)
expr <- expr[asgns]
vapply(expr, function(e) deparse(e[[2]])[1], "")
}
E.g., for the script /tmp/r.R containing
f1 <- function(x)x+1
x <- 10
x1 <- f1(x)
f2 <- function(x)x+1
x2 <- f2(x)
I get:
> namesOfFunctionsDefined(parse("/tmp/r.R"))
[1] "f1" "f2"
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Michael Sent: Tuesday, November 13, 2012 2:08 PM To: Duncan Murdoch Cc: r-help Subject: Re: [R] How do I step thru all lines (including step into sub-routines) in a R script? Is there a way to strip out all functions in hundreds of R script? And then I can create a script which does "debug(foo1); debug(foo2); debug(foo3);",etc? Thank you! On Tue, Nov 13, 2012 at 3:56 PM, Duncan Murdoch <murdoch.duncan at gmail.com>wrote:
On 12-11-13 4:50 PM, Michael wrote:
but there are hundreds of such functions...? how to mark them all using "debug"?
When you see you are about to enter one that you haven't marked, you can mark it from within the debugger. (So in some other debuggers you'd type "s" to step in; in R you need to type "debug(foo)" then "n". Duncan Murdoch thanks!
On Tue, Nov 13, 2012 at 3:43 PM, Duncan Murdoch <murdoch.duncan at gmail.com
<mailto:murdoch.duncan at gmail.**com<murdoch.duncan at gmail.com>>>
wrote:
On 12-11-13 4:05 PM, Michael wrote:
How do I step thru all lines (including step into sub-routines)
in a R
script?
Hi all,
I know I can put a "browser()" into any place...
but how to step into sub-routines?
Keep pressing "n" at the break-point seems not getting me into the
sub-routines?
Mark all your functions for debugging using debug(). It's not like
a debugger that will single step until you tell it to just continue
on, but it gives you the individual steps.
When you've had enough of that, use undebug() to mark the functions
for stepping over.
Duncan Murdoch
[[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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/485ffb24/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/983f7742/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/87bdd4aa/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20121113/7d809564/attachment.pl>