Hi,
I'd like to debug in a loop (using debug() and browser() etc but not print()
). I'am looking for the first occurence of NA.
For instance:
tab = c(1:300)
tab[250] = NA
len = length(tab)
for (i in 1:len){
if(i != len){
tab[i] = tab[i]+tab[i+1]
}
}
I do not want to do "Browse[2]> n" for each step ... I'd like to declare a
"browser()" in the loop with a condition. But how to write "stop running
when you encounter NA" ?
Thanks for your help
--
View this message in context: http://r.789695.n4.nabble.com/debug-in-a-loop-tp4376563p4376563.html
Sent from the R help mailing list archive at Nabble.com.
debug in a loop
3 messages · ikuzar, Justin Haynes, Duncan Murdoch
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120210/8f12b347/attachment.pl>
1 day later
On 12-02-10 12:48 PM, Justin Haynes wrote:
You can add if(is.na(tab[i])) browser() or if(is.na(tab[i])) break see inline
You can also do this temporarily. Supposing that you used
source("foo.R") to enter a function with that code in it, and you want
the check on line 10, you'd enter
setBreakpoint("foo.R#10", tracer=quote(if(is.na(tab[i])) browser()))
Duncan Murdoch
On Fri, Feb 10, 2012 at 7:22 AM, ikuzar<razuki at hotmail.fr> wrote:
Hi,
I'd like to debug in a loop (using debug() and browser() etc but not
print()
). I'am looking for the first occurence of NA.
For instance:
tab = c(1:300)
tab[250] = NA
len = length(tab)
for (i in 1:len){
if(i != len){
if(is.na(tab[i])) browser()
tab[i] = tab[i]+tab[i+1] } } I do not want to do "Browse[2]> n" for each step ... I'd like to declare a "browser()" in the loop with a condition. But how to write "stop running when you encounter NA" ? Thanks for your help -- View this message in context: http://r.789695.n4.nabble.com/debug-in-a-loop-tp4376563p4376563.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.