1

The reprex below results in the error message, "No more error handlers available (recursive errors?); invoking 'abort' restart". This error message only appears when the code is wrapped within a profvis() call. Any insight into why this is happening would be appreciated. My initial suspicion is something to do with the tryCatch() statement.

Code

library(profvis)

n_pred <- c(3,6,12)
pref_prev <- c(0.3, 0.1, 0.01)
scen_temp <- expand.grid(pref_prev = pref_prev, n_pred = n_pred)
par_all <- matrix(NA, nrow = nrow(scen_temp), ncol = 2)
par_init <- matrix(data = c(-1, 0.5,
                            -2.5, 0.5,
                            -5, 0.5,
                            -1, 0.4,
                            -2.5, 0.4,
                            -5, 0.4,
                            -1, 0.3,
                            -2.5, 0.3,
                            -5, 0.3),
                   nrow = 9, ncol = 2, byrow = TRUE)

profvis({

  for (j in 1:nrow(par_all)) {
    
    par_sce <- matrix(NA, 10, 2)
    
    for (k in 1:10){
      par_sce[k,] <- tryCatch({optimB(n_pred = scen_temp[j,2], 
                                      pref_prev = scen_temp[j,1], 
                                      par_init = par_init[j,], 
                                      n = 5000)},
                              error = function(err) {
                                err$message <- paste(err, "Using initial params instead.")
                                par_init[j,]
                              })
    }
    par_all[j,] <- apply(par_sce, 2, median)
  }
})

Session Info

R version 4.2.1 (2022-06-23) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Ventura 13.0.1

Matrix products: default LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages: [1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] compiler_4.2.1 magrittr_2.0.3 fastmap_1.1.0 cli_3.4.1 tools_4.2.1 rstudioapi_0.14 [7] memoise_2.0.1 cachem_1.0.6 conflicted_1.1.0 rlang_1.0.6 purrr_0.3.5

latlio
  • 1,567
  • 7
  • 15

0 Answers0