Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local_trace() #1791

Closed
hadley opened this issue May 22, 2023 · 2 comments
Closed

local_trace() #1791

hadley opened this issue May 22, 2023 · 2 comments
Milestone

Comments

@hadley
Copy link
Member

hadley commented May 22, 2023

From renv:

renv_scope_trace <- function(what, tracer, envir = parent.frame()) {

  call <- sys.call()
  call[[1L]] <- base::trace
  call[["print"]] <- FALSE
  suppressMessages(eval(call, envir = parent.frame()))

  defer(suppressMessages(untrace(substitute(what))), envir = envir)
}
@hadley hadley added this to the 3.1.8 milestone Jun 2, 2023
@hadley
Copy link
Member Author

hadley commented Jun 3, 2023

Hmmmm, this is not as useful as expected because .doTrace's implementation is sub-optimal:

f <- function() {
  "x"
}
trace(f, quote(return("y")))
#> [1] "f"
body(f)
#> {
#>     .doTrace(return("y"), "on entry")
#>     {
#>         "x"
#>     }
#> }
f()
#> Tracing f() on entry
#> [1] "x"


.doTrace <- function(expr, msg) {
  on <- tracingState(FALSE)
  if (on) {
    on.exit(tracingState(TRUE))
    expr
  }
  
  invisible()
}
f()
#> [1] "y"

Created on 2023-06-03 with reprex v2.0.2

@hadley
Copy link
Member Author

hadley commented Jun 5, 2023

We can't figure out a work around, so I think this is unfortunately a deadend.

@hadley hadley closed this as completed Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant