Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Created November 6, 2023 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bohdanszymanik/2019b57bd5396c148bb39d5f04a91e06 to your computer and use it in GitHub Desktop.
Save bohdanszymanik/2019b57bd5396c148bb39d5f04a91e06 to your computer and use it in GitHub Desktop.
From a tibble map a (slow) function over a column to calculate a new column with a progress bar
library(tidyverse)
1:1000 |>
as_tibble_col(column_name="some_column") |>
select(some_column) |>
mutate(some_other_column = map(some_column, function(x){Sys.sleep(1/100);(1/x)}, .progress = list(
type = "iterator",
format = "Calculating {cli::pb_bar} {cli::pb_percent}",
clear = TRUE)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment