futureverse / futureverse/progressr

Suggestion: include a function decorator that works with progressr

Open
#122 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
299
Forks
11
PR merge metrics
No merged PRs in 30d

Description

I was wondering if it would make sense to have a function decorator explicitly for (simple) progress updates, so that I can extend the behaviour of pre-existing functions - something like:

```r
progressively <- function(f, p = NULL){
if(is.null(p)) p <- function(...) NULL
force(f)

function(...){
on.exit(p("loading..."))
f(...)
}

}
```
which then could be called like:

```r
read_rosters <- function(){
urls <- c("https://github.com/nflverse/nflfastR-roster/raw/master/data/seasons/roster_2020.csv", "https://github.com/nflverse/nflfastR-roster/raw/master/data/seasons/roster_2021.csv")
p <- progressor(along = urls)
purrr::map_dfr(urls, progressively(read.csv, p))
}

x <- with_progress(read_rosters())
```

This is inspired by Hadley's notes on function operators in Advanced R, and purrr's `quietly`/`safely` set of decorators

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.