Skip to content

Commit e74be88

Browse files
Merge branch 'release/0.1.5'
2 parents 07f14c1 + b875ed7 commit e74be88

22 files changed

+687
-38
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ Rplots.pdf$
6060
^last.dump*
6161

6262
vignettes/
63-
^.*.gif$
63+
^.*.gif$

.travis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#----------------------------------------------------------------
2+
# Travis-CI configuration for R packages
3+
#
4+
# REFERENCES:
5+
# * Travis CI: https://docs.travis-ci.com/user/languages/r
6+
# * covr: https://github.com/jimhester/covr
7+
#
8+
# Validate your .travis.yml file at http://lint.travis-ci.org/
9+
#----------------------------------------------------------------
10+
language: r
11+
sudo: false
12+
cache: packages
13+
warnings_are_errors: false
14+
r_check_args: --as-cran
15+
latex: false
16+
17+
matrix:
18+
include:
19+
- os: linux
20+
r: oldrel
21+
- os: linux
22+
r: release
23+
- os: linux
24+
r: devel
25+
env:
26+
- R_KEEP_PKG_SOURCE=yes
27+
- _R_S3_METHOD_LOOKUP_BASEENV_AFTER_GLOBALENV_=true
28+
- _R_S3_METHOD_LOOKUP_USE_TOPENV_AS_DEFENV_=true
29+
- _R_CHECK_CONNECTIONS_LEFT_OPEN_=true
30+
- _R_CHECK_LENGTH_1_CONDITION_=true
31+
- _R_CHECK_LENGTH_1_LOGIC2_=true
32+
- os: osx
33+
r: oldrel
34+
- os: osx
35+
r: release
36+
- os: linux
37+
r: release
38+
r_check_args: --no-build-vignettes --no-codoc --no-examples --no-tests --no-manual --ignore-vignettes
39+
r_packages:
40+
- covr
41+
after_success:
42+
- Rscript -e 'covr::codecov(quiet=FALSE)'
43+
env: NB='w/ covr' ## Just a label
44+
45+
notifications:
46+
email:
47+
on_success: change
48+
on_failure: change

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: progressr
2-
Version: 0.1.4
2+
Version: 0.1.5
33
Title: A Unifying API for Progress Updates
44
Description: A minimal API for reporting progress updates upstream. The design is to separate the representation of progress updates from how they are presented. What type of progress to signal is controlled by the developer. How these progress updates are rendered is controlled by the end user. For instance, some users may prefer visual feedback such as a horizontal progress bar in the terminal, whereas others may prefer auditory feedback.
55
Authors@R: c(
@@ -10,6 +10,7 @@ Imports:
1010
digest,
1111
utils
1212
Suggests:
13+
graphics,
1314
tcltk,
1415
beepr,
1516
notifier,
@@ -19,7 +20,8 @@ Suggests:
1920
future,
2021
doFuture,
2122
future.apply,
22-
furrr
23+
furrr,
24+
shiny
2325
Remotes:
2426
gaborcsardi/notifier@d92b1b6
2527
URL: https://github.com/HenrikBengtsson/progressr

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export(progress_handler)
1818
export(progress_progressr)
1919
export(progression)
2020
export(progressor)
21+
export(shiny_handler)
2122
export(slow_sum)
2223
export(tkprogressbar_handler)
2324
export(txtprogressbar_handler)
2425
export(winprogressbar_handler)
26+
export(withProgress2)
2527
export(with_progress)
2628
export(without_progress)
2729
importFrom(digest,digest)

NEWS

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
Package: progressr
22
==================
33

4+
Version: 0.1.5 [2019-10-26]
5+
6+
NEW FEATURES:
7+
8+
* Add withProgress2(), which is a plug-in backward compatibily replacement
9+
for shiny::withProgress() wrapped in progressr::with_progress() where the
10+
the "shiny" progression handler is by default added to the list of
11+
progression handlers used.
12+
13+
* Add demo("mandelbrot", package = "progressr").
14+
15+
BUG FIXES:
16+
17+
* Package could set '.Random.seed' to NULL, instead of removing it, which in
18+
turn would produce a warning on "'.Random.seed' is not an integer vector but
19+
of type 'NULL', so ignored" when the next random number generated.
20+
21+
422
Version: 0.1.4 [2019-07-02]
523

624
NEW FEATURES:

OVERVIEW.md

Lines changed: 120 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Life cycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)
1+
![Life cycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)
22

33
The **[progressr]** package provides a minimal API for reporting progress updates in [R](https://www.r-project.org/). The design is to separate the representation of progress updates from how they are presented. What type of progress to signal is controlled by the developer. How these progress updates are rendered is controlled by the end user. For instance, some users may prefer visual feedback such as a horizontal progress bar in the terminal, whereas others may prefer auditory feedback.
44

@@ -26,7 +26,7 @@ Assume that we have a function `slow_sum()` for adding up the values in a vector
2626

2727
```r
2828
slow_sum <- function(x) {
29-
progress <- progressr::progressor(length(x))
29+
progress <- progressr::progressor(along = x)
3030
sum <- 0
3131
for (kk in seq_along(x)) {
3232
Sys.sleep(0.1)
@@ -105,24 +105,53 @@ handlers("txtprogressbar", "beepr")
105105

106106
## Support for progressr elsewhere
107107

108-
### The plyr package
108+
Note that progression updates by **progressr** is designed to work out of the box for any _sequential_ iterator framework in R. Here is an set of examples for the most common ones:
109109

110-
The functions in the [**plyr**](https://cran.r-project.org/package=plyr) package take argument `.progress`, which can be used to produce progress updates. To have them generate **progressr** 'progression' updates, use `.progress = "progressr"`. For example,
111110
```r
112111
library(progressr)
112+
113+
xs <- 1:5
114+
y_truth <- lapply(xs, slow_sqrt)
115+
113116
with_progress({
114-
y <- plyr::l_ply(1:5, function(x, ...) {
115-
Sys.sleep(1)
117+
p <- progressor(along = xs)
118+
y <- lapply(xs, function(x) {
119+
p(sprintf("x=%g", x))
120+
Sys.sleep(0.1)
116121
sqrt(x)
117-
}, .progress = "progressr")
122+
})
123+
})
124+
125+
library(foreach)
126+
with_progress({
127+
p <- progressor(along = xs)
128+
y <- foreach(x = xs) %do% {
129+
p(sprintf("x=%g", x))
130+
Sys.sleep(0.1)
131+
sqrt(x)
132+
}
133+
})
134+
135+
library(purrr)
136+
with_progress({
137+
p <- progressor(along = xs)
138+
y <- map(xs, function(x) {
139+
p(sprintf("x=%g", x))
140+
Sys.sleep(0.1)
141+
sqrt(x)
142+
})
118143
})
119-
## |===================== | 40%
120144
```
121145

122146

123-
### The future framework
147+
### Parallel processing and progress updates
148+
149+
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]**.
150+
151+
152+
#### future_lapply() - parallel lapply()
124153

125-
The **[future]** framework has built-in support for the kind of progression updates produced by the **progressr** package. Here is an example that uses `future_lapply()` of the **[future.apply]** package to parallelize on the local machine while at the same time signaling progression updates:
154+
Here is an example that uses `future_lapply()` of the **[future.apply]** package to parallelize on the local machine while at the same time signaling progression updates:
126155

127156
```r
128157
library(future.apply)
@@ -131,18 +160,92 @@ plan(multisession)
131160
library(progressr)
132161
handlers("progress", "beepr")
133162

163+
xs <- 1:5
164+
134165
with_progress({
135-
p <- progressr::progressor(5)
136-
y <- future_lapply(1:5, function(x, ...) {
166+
p <- progressor(along = xs)
167+
y <- future_lapply(xs, function(x, ...) {
137168
p(sprintf("x=%g", x))
138-
Sys.sleep(1)
169+
Sys.sleep(6.0-x)
139170
sqrt(x)
140171
})
141172
})
142173
## [=================>-----------------------------] 40% x=2
143174
```
144175

145176

177+
#### foreach() with doFuture
178+
179+
Here is an example that uses `foreach()` of the **[foreach]** package to parallelize on the local machine (via **[doFuture]**) while at the same time signaling progression updates:
180+
181+
```r
182+
library(doFuture)
183+
registerDoFuture()
184+
plan(multisession)
185+
186+
library(progressr)
187+
handlers("progress", "beepr")
188+
189+
xs <- 1:5
190+
191+
with_progress({
192+
p <- progressor(along = xs)
193+
y <- foreach(x = xs) %dopar% {
194+
p(sprintf("x=%g", x))
195+
Sys.sleep(6.0-x)
196+
sqrt(x)
197+
}
198+
})
199+
## [=================>-----------------------------] 40% x=2
200+
```
201+
202+
203+
#### future_map() - parallel purrr::map()
204+
205+
```r
206+
library(furrr)
207+
plan(multisession)
208+
209+
library(progressr)
210+
handlers("progress", "beepr")
211+
212+
xs <- 1:5
213+
214+
with_progress({
215+
p <- progressor(along = xs)
216+
y <- future_map(xs, function(x) {
217+
p(sprintf("x=%g", x))
218+
Sys.sleep(6.0-x)
219+
sqrt(x)
220+
})
221+
})
222+
## [=================>-----------------------------] 40% x=2
223+
```
224+
225+
226+
### The plyr package
227+
228+
The functions in the [**plyr**](https://cran.r-project.org/package=plyr) package take argument `.progress`, which can be used to produce progress updates. To have them generate **progressr** 'progression' updates, use `.progress = "progressr"`. For example,
229+
```r
230+
library(plyr)
231+
library(progressr)
232+
233+
xs <- 1:5
234+
235+
with_progress({
236+
y <- l_ply(xs, function(x, ...) {
237+
Sys.sleep(6.0-x)
238+
sqrt(x)
239+
}, .progress = "progressr")
240+
})
241+
## |===================== | 40%
242+
```
243+
244+
_Comment_: This also works when using `.parallel = TRUE` with a **[foreach]** parallel-backend such as **[doParallel]** or **[doFuture]** registered.
245+
246+
247+
248+
146249

147250
## Roadmap
148251

@@ -201,3 +304,7 @@ To debug progress updates, use:
201304
[progress]: https://cran.r-project.org/package=progress
202305
[future]: https://cran.r-project.org/package=future
203306
[future.apply]: https://cran.r-project.org/package=future.apply
307+
[doFuture]: https://cran.r-project.org/package=doFuture
308+
[foreach]: https://cran.r-project.org/package=foreach
309+
[furrr]: https://cran.r-project.org/package=furrr
310+

0 commit comments

Comments
 (0)