Skip to content

Commit

Permalink
README: mention new 'knitr.progress.fun' feature in knitr (fix #148)
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Nov 25, 2022
1 parent b83a4bc commit 07df58f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,34 @@ my_fcn(1:5)
Note how this solution does not make use of **plyr**'s `.progress` argument, because the above solution is more powerful and more flexible, e.g. we have more control on progress updates and their messages. However, if you prefer the traditional **plyr** approach, you can use `.progress = "progressr"`, e.g. `y <- llply(..., .progress = "progressr")`.




### The knitr package

When compiling ("knitting") an knitr-based vignette, for instance, via
`knitr::knit()`, **[knitr]** shows the progress of code chunks
processed thus far using a progress bar. In **knitr** (>= 1.42) [to
be released], we can use **progressr** for this progress reporting.
To do this, set R option `knitr.progress.fun` as:

```r
options(knitr.progress.fun = function(total, labels) {
p <- progressr::progressor(total, on_exit = FALSE)
list(
update = function(i) p(sprintf("chunk: %s", labels[i])),
done = function() p(type = "finish")
)
})
```

This configures **knitr** to signal progress via the **progressr**
framework. To report on these, use:

```r
progressr::handlers(global = TRUE)
```


## Parallel processing and progress updates

The **[future]** framework, which provides a unified API for parallel and distributed processing in R, has built-in support for the kind of progression updates produced by the **progressr** package. This means that you can use it with for instance **[future.apply]**, **[furrr]**, and **[foreach]** with **[doFuture]**, and **[plyr]** or **[BiocParallel]** with **doFuture**. In contrast, _non-future_ parallelization methods such as **parallel**'s `mclapply()` and, `parallel::parLapply()`, and **foreach** adapters like **doParallel** do _not_ support progress reports via **progressr**.
Expand Down Expand Up @@ -737,12 +765,12 @@ M: Added value 3
[doParallel]: https://cran.r-project.org/package=doParallel
[doFuture]: https://cran.r-project.org/package=doFuture
[furrr]: https://cran.r-project.org/package=furrr
[knitr]: https://cran.r-project.org/package=knitr
[pbapply]: https://cran.r-project.org/package=pbapply
[pbmcapply]: https://cran.r-project.org/package=pbmcapply
[plyr]: https://cran.r-project.org/package=plyr
[BiocParallel]: https://www.bioconductor.org/packages/BiocParallel/


## Installation
R package progressr is available on [CRAN](https://cran.r-project.org/package=progressr) and can be installed in R as:
```r
Expand Down
30 changes: 29 additions & 1 deletion incl/OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,34 @@ my_fcn(1:5)
Note how this solution does not make use of **plyr**'s `.progress` argument, because the above solution is more powerful and more flexible, e.g. we have more control on progress updates and their messages. However, if you prefer the traditional **plyr** approach, you can use `.progress = "progressr"`, e.g. `y <- llply(..., .progress = "progressr")`.




### The knitr package

When compiling ("knitting") an knitr-based vignette, for instance, via
`knitr::knit()`, **[knitr]** shows the progress of code chunks
processed thus far using a progress bar. In **knitr** (>= 1.42) [to
be released], we can use **progressr** for this progress reporting.
To do this, set R option `knitr.progress.fun` as:

```r
options(knitr.progress.fun = function(total, labels) {
p <- progressr::progressor(total, on_exit = FALSE)
list(
update = function(i) p(sprintf("chunk: %s", labels[i])),
done = function() p(type = "finish")
)
})
```

This configures **knitr** to signal progress via the **progressr**
framework. To report on these, use:

```r
progressr::handlers(global = TRUE)
```


## Parallel processing and progress updates

The **[future]** framework, which provides a unified API for parallel and distributed processing in R, has built-in support for the kind of progression updates produced by the **progressr** package. This means that you can use it with for instance **[future.apply]**, **[furrr]**, and **[foreach]** with **[doFuture]**, and **[plyr]** or **[BiocParallel]** with **doFuture**. In contrast, _non-future_ parallelization methods such as **parallel**'s `mclapply()` and, `parallel::parLapply()`, and **foreach** adapters like **doParallel** do _not_ support progress reports via **progressr**.
Expand Down Expand Up @@ -729,8 +757,8 @@ M: Added value 3
[doParallel]: https://cran.r-project.org/package=doParallel
[doFuture]: https://cran.r-project.org/package=doFuture
[furrr]: https://cran.r-project.org/package=furrr
[knitr]: https://cran.r-project.org/package=knitr
[pbapply]: https://cran.r-project.org/package=pbapply
[pbmcapply]: https://cran.r-project.org/package=pbmcapply
[plyr]: https://cran.r-project.org/package=plyr
[BiocParallel]: https://www.bioconductor.org/packages/BiocParallel/

0 comments on commit 07df58f

Please sign in to comment.