I want to use the foreach
package in conjunction with logging. I usually use the futile.logger
package. When work is given to the workers logging information is lost (which is strange as you need to indicate to foreach the logging package)
I've seen this post but it does not use foreach
library(foreach)
library(futile.logger)
library(doParallel)
flog.threshold(DEBUG)
cluster <- makeCluster(8)
registerDoParallel(cluster)
doStuff <- function(input){
flog.debug('Doing some stuff with %s', input)
return(input)
}
res <- lapply(FUN=doStuff, X=seq(1,8,1))
# >> this prints
res2 <- foreach(input = seq(1,8,1)) %do% doStuff(input)
# >> this prints
res3 <- foreach(input = seq(1,8,1), .packages='futile.logger') %dopar% doStuff(input)
# >> this does not
identical(res,res2) && identical(res,res3)
I do not really care about the parallele backend, can be anything, but how can I symply get the logging working