It seems to be a bug about "base::trace()" or "methods:::.TraceWithMethods()"?

27 views Asked by At

I wish to write a function and use the "trace()" method inside the function, like this :

library(IRanges)
mf <- function(){
  insert.expr <- quote(message("tracing ..."))
  trace(what = "findOverlaps", 
        signature = c("IntegerRanges", "IntegerRanges"), 
        tracer = insert.expr, edit = TRUE, print = FALSE)
}

When I executed this function, I found the following situation (marked by the arrow): enter image description here

When I call the function I want to trace:

mf()
query <- IRanges(c(1, 3, 9), c(1, 4, 11))
subject <- IRanges(c(2, 2, 10), c(2, 4, 12))
findOverlaps(query, subject, type = "within")

the following error is thrown:

Error in eval(expr, p) : Object 'insert.expr' not found

I looked at the source code of the "trace()" method and found that the problem occurred in the "methods:::.TraceWithMethods()" method:

In Rstudio, the problematic code appears on line 126, I think the "substitute()" function should not be used here. enter image description here

The problem was indeed solved when I changed "substitute(tracer)" to "tracer".

I'm not sure if this is a bug in the method itself, if not I'm hoping to find a workaround here.

0

There are 0 answers