Antoine Fabri
2020-Aug-25 20:02 UTC
[Rd] trace creates object in base namespace if called on function argument
Dear R-devel, I don't think this is expected : foo <- function() "hello" trace2 <- function(fun) trace(fun, quote(print("!!!"))) base::fun # Object with tracing code, class "functionWithTrace" # Original definition: # function() "hello" # # ## (to see the tracing code, look at body(object)) `untrace()` has the same behavior. This is inconsistent with how debug works : foo <- function() "hello" debug2 <- function(fun) debug(fun) debug2(foo) isdebugged(foo) # [1] TRUE This can be worked around by defining : trace2 <- function(fun) eval.parent(substitute(trace(fun, quote(print("!!!"))) but I believe the current behavior is undesired and it'd be better to make it behave as `debug()`, or to throw an error. Best, Antoine [[alternative HTML version deleted]]
Antoine Fabri
2020-Aug-26 01:31 UTC
[Rd] trace creates object in base namespace if called on function argument
Apologies there is one line missing in my last email, the code should be : foo <- function() "hello" trace2 <- function(fun) trace(fun, quote(print("!!!"))) trace2(foo) # <- THIS LINE WAS MISSING base::fun Best, Antoine Le mar. 25 ao?t 2020 ? 22:02, Antoine Fabri <antoine.fabri at gmail.com> a ?crit :> Dear R-devel, > > I don't think this is expected : > > foo <- function() "hello" > trace2 <- function(fun) trace(fun, quote(print("!!!"))) > base::fun > # Object with tracing code, class "functionWithTrace" > # Original definition: > # function() "hello" > # > # ## (to see the tracing code, look at body(object)) > > `untrace()` has the same behavior. > > This is inconsistent with how debug works : > > foo <- function() "hello" > debug2 <- function(fun) debug(fun) > debug2(foo) > isdebugged(foo) > # [1] TRUE > > This can be worked around by defining : > > trace2 <- function(fun) eval.parent(substitute(trace(fun, > quote(print("!!!"))) > > but I believe the current behavior is undesired and it'd be better to make > it behave as `debug()`, or to throw an error. > > Best, > > Antoine >[[alternative HTML version deleted]]
Tomas Kalibera
2020-Aug-26 12:17 UTC
[Rd] trace creates object in base namespace if called on function argument
Please note that this is documented in ?trace. "fun" is matched to what, it is a _name_ of the function to be traced, which is traced in the top-level environment. I don't know why it was designed this way, but it is documented in detail, and hence the expected behavior. Debugging is often, and also in R, implemented in the core. Tracing is implemented on top without specific support, it thus cannot do some things debugging can do. Tomas On 8/26/20 3:31 AM, Antoine Fabri wrote:> Apologies there is one line missing in my last email, the code should be : > > foo <- function() "hello" > trace2 <- function(fun) trace(fun, quote(print("!!!"))) > trace2(foo) # <- THIS LINE WAS MISSING > base::fun > > Best, > > Antoine > > Le mar. 25 ao?t 2020 ? 22:02, Antoine Fabri <antoine.fabri at gmail.com> a > ?crit : > >> Dear R-devel, >> >> I don't think this is expected : >> >> foo <- function() "hello" >> trace2 <- function(fun) trace(fun, quote(print("!!!"))) >> base::fun >> # Object with tracing code, class "functionWithTrace" >> # Original definition: >> # function() "hello" >> # >> # ## (to see the tracing code, look at body(object)) >> >> `untrace()` has the same behavior. >> >> This is inconsistent with how debug works : >> >> foo <- function() "hello" >> debug2 <- function(fun) debug(fun) >> debug2(foo) >> isdebugged(foo) >> # [1] TRUE >> >> This can be worked around by defining : >> >> trace2 <- function(fun) eval.parent(substitute(trace(fun, >> quote(print("!!!"))) >> >> but I believe the current behavior is undesired and it'd be better to make >> it behave as `debug()`, or to throw an error. >> >> Best, >> >> Antoine >> > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel