Skip to content

Instantly share code, notes, and snippets.

@angelotrivelli
Last active August 26, 2023 23:51
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 angelotrivelli/1c3f0950e0324e3729e673809a0d7e9a to your computer and use it in GitHub Desktop.
Save angelotrivelli/1c3f0950e0324e3729e673809a0d7e9a to your computer and use it in GitHub Desktop.
pmap is confusing part 2
library(tidyverse)
bdr <- tcm_files |>
distinct(batch, device, run)
walk(unique(bdr$batch), ~ dir.create(file.path(pipeline_step_02, .),
recursive = TRUE,
showWarnings = FALSE))
package_bdr <- function(batch, device, run, dataset) {
w <- map(dataset, \(x) filter(x,
batch == batch &
device == device &
runl == run))
rds_filepath <- paste0(device, '_run', run, '_', batch, '.rds')
walk(w, ~ write_rds(., file.path(pipeline_step_02, batch, rds_filepath)))
success <- list(file.exists(file.path(pipeline_step_02, batch, rds_filepath)))
names(success) <- paste(batch, device, run, collapse = ' ')
return(success)
}
q <- pmap(bdr, package_bdr, dataset = tcm_dataset) |> unlist()
cat(paste('all files written successfully? ', all(q), collapse= ' '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment