[Rd] Unexpected behavior of debug() in step-wise mode

Duncan Murdoch murdoch.duncan at gmail.com
Wed Dec 31 23:11:22 CET 2014


On 31/12/2014 4:06 PM, Levi Waldron wrote:
> Why does debug() enter Browse[3] here at all, and why does it happen the
> first time and not the second? This seems unexpected to me, and has
> undesirable effects for ESS users (that I reported here -
> https://stat.ethz.ch/pipermail/ess-help/2013-June/009154.html - but just
> realized my post to r-devel didn't make it through when I tried to report
> it back then).
> 

Looks like a bug.  I haven't looked at the source, but I would guess
that the { function is being treated specially when you enter the
function, since usually it's the first thing called in the body.

Since you mention ESS, I'm guessing the {n+2} is automatically
generated, it's not typed by the user. You might be able to generate
some equivalent code instead, e.g.

eval(expression(n+2))


Duncan Murdoch

>> Fun <- function(n) print(n)
>> debug(Fun)
>> Fun(2)
> debugging in: Fun(2)
> debug: print(n)
> Browse[2]> {n+2}
> debug at #1: n + 2
> Browse[3]> c
> [1] 4
> Browse[2]> {n+2}
> [1] 4
> Browse[2]> sessionInfo()
> R version 3.1.2 (2014-10-31)
> Platform: x86_64-apple-darwin13.4.0 (64-bit)
> 
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list