Skip to contents

Some functions in this packages will take some time to run, e.g computing the OC probabilities with multi-stage ORR Go/Nogo design (OC_Compute_Prob(), called by OC_Curve_Diff_Rules2()), or the OC of TTE Go/Nogo design based on simulation (PFS_OC_Curve_Data(), called by PFS_OC_Curve_Diff_Rules()). These computation will report progress info and this is a guide on how to listen to these progress info.

Run those functions interactivly

The progress info is implemented based on the progressr framework. So in your R session, you can set a progress handler according to your needs.

library(progressr)     # The default is a text-based handler
handlers("cli")        # The `cli` handler, requires the `cli` package to be installed.
handlers("rstudio")    # The `rstudio` handler, reuqires to run in RStudio

Then you can explicitly listen to progress information with with_progress

with_progress({
    # Please put the script that you want to listen to progress info here
})

Or if you’re using R >= 4.1, you can enable the global handlers

handlers(global = TRUE)    # By this way, you will listen to all provided progress info
                           #   even without using `with_progress`

This scenario also includes calling rmarkdown::render in your current R session.

For more details about how to use the progressr framework, please refer to progressr’s website

Render report with Knit button in RStudio

The Knit button in RStudio when writing Rmd will start a special R session in NON-interactive mode. Also, knitr::knit will report its own progress. So if your want to also listen to your detailed progress report during the computation, you need to

  1. Enable progressr in non-interactive session via environment variable R_PROGRESSR_ENABLE

    Sys.setenv(R_PROGRESSR_ENABLE = TRUE)
  2. Set the progress bar like that in interactive mode before in your Rmd report. Note: It’s recommended to use cli or rstudio handlers in your Rmd report. The default txtprogressbar handler or progress handler seems to conflict with knitr’s progress, or might end up been rendered into the resulting report, which is not wanted.

Render Rmd report in for-loop with xfun::Rscript_call or callr::r

If you want to avoid polluting environment during rendering Rmd report, you can always use xfun::Rscript_call or callr::r to call rmarkdown::render. But in this case, the showing of progress bar is more complicated.

  1. Like before, set the R_PROGRESSR_ENABLE to TRUE

    Sys.setenv(R_PROGRESSR_ENABLE = TRUE)
  2. For xfun::Rscript_call, currently my solution is to submit it as Background Jobs in the Rstudio background job pane of RStudio. Then rendered progress bar might not be perfect, but at least it provides some progress other than the simple progress info when directly running Rscript_call.

  3. When using callr::r, I’m suggesting the script template

      Sys.setenv(R_PROGRESSR_ENABLE = TRUE)
      callr::r(
          function(...){
              rmarkdown::render(...)
          } , 
          list(
              input = "./your_rmd_report.Rmd"
          ), 
          show = TRUE)