Parallel processing pandoc有时无法找到utf8.md文件
我有一个R代码,它在一个循环中呈现几个rmarkdown HTML报告。 这大致就是循环中的代码:Parallel processing pandoc有时无法找到utf8.md文件,parallel-processing,r-markdown,pandoc,Parallel Processing,R Markdown,Pandoc,我有一个R代码,它在一个循环中呈现几个rmarkdown HTML报告。 这大致就是循环中的代码: knitr::knit_meta(class=NULL, clean = TRUE) rmarkdown::render(input =paste0("10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd"), output_file = paste0(reportPath), params = list(MyDataFrame = MyDataFr
knitr::knit_meta(class=NULL, clean = TRUE)
rmarkdown::render(input =paste0("10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd"), output_file = paste0(reportPath), params = list(MyDataFrame = MyDataFrame[i]))
MyDataFrame[i]的意思是,输入data.frame在每个循环迭代中都是不同的
我让这段代码在AWS服务器上运行,在多个核心上并行运行。所谓并行,我的意思是,我的代码在多个线程中同时运行,但输入数据不同
有时运行时不会出现问题,但有时会出现以下错误:
pandoc: 10_01_ReportingPortfoliosHTML.utf8.md: openBinaryFile: does not exist (No such file or directory)
你知道为什么会发生这种情况,为什么不经常发生
更新:
经过进一步的调查,我发现所有并行线程都使用相同的工作目录,并且正在使用相同的名称创建knitr元数据。这就是为什么如果一个线程清除所有元数据,它也会在其他线程中消失。此外,如果我不清理元数据,我会得到不同线程的数据的疯狂混合: 我以一种丑陋的方式解决了这个问题,将每个并行进程的代码复制到一个单独的目录中,并使用唯一的名称将其设置为该进程的工作目录。完成此过程后,此唯一临时创建的工作目录将被擦除:
libPath = "Some/Unique/directory"
system(paste0("cp ", R_FUNCTIONS_PATH, "10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd ", libPath, "/"), intern = T)
rmarkdown::render(input =paste0(libPath, "/10_01_ReportingPortfoliosHTML.Rmd"), output_file = paste0(reportPath), params = list(MyDataFrame = MyDataFrame[i]))
knitr::knit_meta(class=NULL, clean = TRUE)
system(paste0("rm -r ", libPath), intern = T)
libPath = "Some/Unique/directory"
system(paste0("cp ", R_FUNCTIONS_PATH, "10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd ", libPath, "/"), intern = T)
rmarkdown::render(input =paste0(libPath, "/10_01_ReportingPortfoliosHTML.Rmd"),
output_file = paste0(reportPath),
params = list(MyDataFrame = MyDataFrame[i]))
knitr::knit_meta(class=NULL, clean = TRUE)
system(paste0("rm -r ", libPath), intern = T)
我的最新问题:是否有其他可能将工作目录设置为与
render()
函数中的“input”参数不同的位置(与.Rmd代码位置不同的位置)?经过进一步调查,我发现所有并行线程都使用相同的工作目录,并使用相同的名称创建knitr元数据。这就是为什么如果一个线程清除所有元数据,它也会在其他线程中消失。此外,如果我不清理元数据,我会得到不同线程的数据的疯狂混合:我以一种丑陋的方式解决了它,将每个并行进程的代码复制到一个具有唯一名称的单独目录中,并将其设置为该进程的工作目录。完成此过程后,此唯一临时创建的工作目录将被擦除:
libPath = "Some/Unique/directory"
system(paste0("cp ", R_FUNCTIONS_PATH, "10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd ", libPath, "/"), intern = T)
rmarkdown::render(input =paste0(libPath, "/10_01_ReportingPortfoliosHTML.Rmd"), output_file = paste0(reportPath), params = list(MyDataFrame = MyDataFrame[i]))
knitr::knit_meta(class=NULL, clean = TRUE)
system(paste0("rm -r ", libPath), intern = T)
libPath = "Some/Unique/directory"
system(paste0("cp ", R_FUNCTIONS_PATH, "10_ReportingHTML/10_01_ReportingPortfoliosHTML.Rmd ", libPath, "/"), intern = T)
rmarkdown::render(input =paste0(libPath, "/10_01_ReportingPortfoliosHTML.Rmd"),
output_file = paste0(reportPath),
params = list(MyDataFrame = MyDataFrame[i]))
knitr::knit_meta(class=NULL, clean = TRUE)
system(paste0("rm -r ", libPath), intern = T)