Skip to content

Commit 3a32777

Browse files
committed
stop if any input files fail on load/processing
1 parent 35b3206 commit 3a32777

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

facebook/delphiFacebook/R/responses.R

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,29 @@
1818
#' @export
1919
load_responses_all <- function(params, contingency_run = FALSE) {
2020
msg_plain(paste0("Loading ", length(params$input), " CSVs"))
21-
22-
map_fn <- if (params$parallel) { mclapply } else { lapply }
21+
22+
# To prevent errors from one file from "contaminating" output for other files
23+
# that happen to be in the same `mclapply` group, turn `mc.preschedule` off.
24+
# This makes debugging problematic input files easier.
25+
# See https://stackoverflow.com/questions/18330274/an-error-in-one-job-contaminates-others-with-mclapply
26+
# for details.
27+
mclapply_no_preschedule <- function(...) {
28+
mclapply(..., mc.preschedule = FALSE)
29+
}
30+
31+
map_fn <- if (params$parallel) { mclapply_no_preschedule } else { lapply }
2332
input_data <- map_fn(seq_along(params$input), function(i) {
2433
load_response_one(params$input[i], params, contingency_run)
2534
})
2635

2736
msg_plain(paste0("Finished loading CSVs"))
37+
38+
which_errors <- unlist(lapply(input_data, inherits, "try-error"))
39+
if (any( which_errors )) {
40+
errored_filenames <- paste(params$input[which_errors], collapse=", ")
41+
stop(paste("ingestion and field creation failed for input data file(s)", errored_filenames))
42+
}
43+
2844
input_data <- bind_rows(input_data)
2945
msg_plain(paste0("Finished combining CSVs"))
3046
return(input_data)

0 commit comments

Comments
 (0)