R: Render_site does not work with Dopar

I have a problem with Render_site using dopar foreach. The code works fine, using simple for. While I was having trouble using dopar, since the duplicate is duplicated after using dopar in the YAML file.

Note that dopar works correctly if I use Render instead of Render_site.

Below you can see my code:

pacman::p_load(data.table) pacman::p_load(data.table,rmarkdown) pacman::p_load(rmarkdown,knitr,kableExtra,dplyr) info.rmd=readLines("test.rmd",encoding = "UTF-8") yml=readLines("site.yml",encoding = "UTF-8") fun<-function(r){ out <- file( description=paste0(r,"test_.Rmd"), open="w", encoding="UTF-8") write(info.rmd,file=out ) close(con=out) render_site(paste0(r,"test_.Rmd"),encoding = "UTF-8",quiet = T) file.remove(paste0(r,"test_.Rmd")) } 

Function works for easy for

 # Working with for for (r in 1:10){ fun(r) } 

I have a problem using dopar (duplicating output to a YAML file in this case)

 # Not working for dopar library(doParallel) no_cores<-3 cl <- makeCluster(no_cores, type="SOCK") registerDoParallel(cl) res<-foreach (r=1:10,.combine = c,.inorder = T) %dopar% { library(rmarkdown) fun(r) } print(ret) stopCluster(cl) 

The trace message is as follows:

 Error in { : task 10 failed - "Duplicate map key: 'output'" 4.stop(simpleError(msg, call = expr)) 3.e$fun(obj, substitute(ex), parent.frame(), e$data) 2.foreach(r = 1:10, .combine = c, .inorder = T) %dopar% { library(rmarkdown) out <- file(description = paste0(r, "test_.Rmd"), open = "w", encoding = "UTF-8") ... 1.system.time(foreach(r = 1:10, .combine = c, .inorder = T) %dopar% { library(rmarkdown) out <- file(description = paste0(r, "test_.Rmd"), open = "w", ... Timing stopped at: 0.39 0.36 7.9 

Then we can see that the _site.yml file is automatically changed using the render_site function.

+7
parallel-processing r yaml r-markdown doparallel
source share

No one has answered this question yet.

See related questions:

eighteen
Why is foreach% dopar% getting slower with every additional node?
2
% dopar% does not work after loading a dataset that comes from another session
one
RWeka will not work with the carriage, or possibly% extra%
one
Problem using R6 and foreach ()% dopar% classes together
one
R foreach could not find function "% dopar%"
0
R foreach% dopar% Results
0
foreach and dopar do not create objects, but return NULL
0
% do% Vs. % dopar%,% dopar% makes no changes, no warnings
0
foreach: code produces different results with% do% and% dopar%
0
Optimize Dopar R

All Articles