Last active
August 26, 2023 23:51
-
-
Save angelotrivelli/1c3f0950e0324e3729e673809a0d7e9a to your computer and use it in GitHub Desktop.
pmap is confusing part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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