I am trying to run this simple for loop as a parallel process as it requires lots of compute power. Any thoughts?
##Load files and libraries---
library(tidyverse)
library(caret)
library(insight)
library(MASS)
library(mfx)
library(furrr)
for (i in 1:16) {
nested_inter$model[[i]]<- nb_thesis_inter(df= nested_nb$data[[i]], mdl= nested_nb$model[[i]])
print (paste("Finished model ", i, "out of 16"))
}
#nested_inter<- nested_inter %>%
# mutate(model= future_map2(.x= data, .y=model, .f = nb_thesis_inter))
My go to is the
future.apply
package.Two things to note.
plan(multisession)
allows Windows to be used in parallel. See?plan
for all options.future_Map
call may need to be changed tofuture_map(function (x, y) nb_thesis_inter(df = x, mdl = y), ...)
depending on the default argument order ofnb_thesis_inter
.