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.