Riksrevisjonen / pioneeR

R package for running a Shiny app for DEA analysis
https://riksrevisjonen.github.io/pioneeR/
8 stars 2 forks source link

Efficiency scores are not shown if `dea.slack` returns `NULL` #25

Closed ohjakobsen closed 1 year ago

ohjakobsen commented 1 year ago

In some circumstances, the function dea.slack can return a null-value. This will break the app with the error message Error in if: missing value where TRUE/FALSE needed?. The bug is not reproducible for all files, so a fix can be difficult to find. A more simple approach would be to catch a null-value and prompt the user with a warning that slack values could not be estimated.

ohjakobsen commented 1 year ago

The error actually happens in the Benchmarking package and is probably due to a change in how R validates if-statements. The workaround for this is to wrap the slack function in a tryCatch and return NULL if the function fails with a warning or error, like this:

dea.slack <- reactive({
  x <- tryCatch({
    Benchmarking::slack(dea.in(), dea.out(), dea.prod())
  }, warning = function(e) {
    NULL
  }, error = function(e) {
    NULL
  })
  x
})