[Rd] trace creates object in base namespace if called on function argument

Antoine Fabri @nto|ne@|@br| @end|ng |rom gm@||@com
Wed Aug 26 03:31:18 CEST 2020


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 using 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]]



More information about the R-devel mailing list