r-lib / rlang

Low-level API for programming with R
https://rlang.r-lib.org
Other
502 stars 140 forks source link

`global_entrace()` cannot be used with other CallingHandlers #1644

Closed DanChaltiel closed 1 year ago

DanChaltiel commented 1 year ago

Hi,

It seems that the very useful global_entrace() forbid the use of other handlers in some contexts.

callr::r(\(){
  library(tidyverse) |> 
    suppressPackageStartupMessages()
})
#>  [1] "lubridate" "forcats"   "stringr"   "dplyr"     "purrr"     "readr"    
#>  [7] "tidyr"     "tibble"    "ggplot2"   "tidyverse" "stats"     "graphics" 
#> [13] "grDevices" "utils"     "datasets"  "methods"   "base"

callr::r(\(){
  rlang::global_entrace()
  library(tidyverse) |> 
    suppressPackageStartupMessages()
}) 
#> Error: ! in callr subprocess.
#> Caused by error in `globalCallingHandlers(error = function (cnd) ...`:
#> ! should not be called with handlers on the stack

Created on 2023-07-28 with reprex v2.0.2

However, this reprex is not 100% reproducible in the console (i.e outside callr), so here is a step list to reproduce the error:

This is actually the steps that got me the error. I'm using rlang v1.1.0 with R 4.1.3.

lionel- commented 1 year ago

Unfortunately this is a limitation of base::globalCallingHandlers() that rlang can't work around.