@@ -125,13 +125,7 @@ Mod_Merge_Chains <- function(
125125
126126 # # ..................................................................... ###
127127
128- Model_Info2 <- IASDT.R :: LoadAs(Path_ModInfo ) %> %
129- dplyr :: mutate(
130- # Check if any posterior files is missing
131- Post_Missing = purrr :: map_lgl(
132- .x = Post_Path , .f = ~ ! any(file.exists(.x ))),
133- # delete these columns if already exist from previous function execution
134- Path_FittedMod = NULL , Path_Coda = NULL )
128+ Model_Info2 <- IASDT.R :: LoadAs(Path_ModInfo )
135129
136130 # Prepare working on parallel -----
137131 if (NCores == 1 ) {
@@ -146,6 +140,38 @@ Mod_Merge_Chains <- function(
146140 on.exit(future :: plan(" future::sequential" , gc = TRUE ), add = TRUE )
147141 }
148142
143+
144+ # Check if any posterior files is missing
145+ Model_Info2 <- Model_Info2 %> %
146+ dplyr :: mutate(
147+ Post_Missing = furrr :: future_map_lgl(
148+ .x = Post_Path ,
149+ .f = function (x ){
150+
151+ purrr :: map_lgl(
152+ .x = as.character(x ),
153+ .f = function (y ) {
154+
155+ if (isFALSE(fs :: file_exists(y ))) {
156+
157+ return (TRUE )
158+
159+ } else {
160+
161+ if (IASDT.R :: CheckRDS(y )) {
162+ return (FALSE )
163+ } else {
164+ fs :: file_delete(y )
165+ return (TRUE )
166+ }
167+
168+ }
169+ }) %> %
170+ any()
171+ }),
172+ # delete these columns if already exist from previous function execution
173+ Path_FittedMod = NULL , Path_Coda = NULL )
174+
149175 # # ..................................................................... ###
150176
151177 # Merge posteriors and save as Hmsc model / coda object
@@ -155,9 +181,10 @@ Mod_Merge_Chains <- function(
155181 FUN = function (x ) {
156182
157183 if (Model_Info2 $ Post_Missing [[x ]]) {
158- return (list (
159- Path_FittedMod = NA_character_ ,
160- Path_Coda = NA_character_ , Post_Aligned2 = NA ))
184+ return (
185+ list (
186+ Path_FittedMod = NA_character_ ,
187+ Path_Coda = NA_character_ , Post_Aligned2 = NA ))
161188 }
162189
163190 # # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@@ -272,7 +299,8 @@ Mod_Merge_Chains <- function(
272299 },
273300 future.scheduling = Inf , future.seed = TRUE ,
274301 future.globals = c(
275- " Model_Info2" , " Path_Fitted_Models" , " FromJSON" , " Path_Coda" ),
302+ " Extension" , " Model_Info2" , " Path_Fitted_Models" ,
303+ " FromJSON" , " Path_Coda" ),
276304 future.packages = c(" Hmsc" , " coda" , " purrr" , " IASDT.R" , " dplyr" ))
277305
278306 if (NCores > 1 ) {
0 commit comments