I've created a simple example showing the problem I currently have.
I have a R-markdown file, named example.Rmd, containing the following code
```{r}
plot(rnorm(10000))
```
and a Makefile file with the following content
all : example01.html example02.html
example01.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example01.html')"
example02.html : example.Rmd
Rscript -e "library(knitr); knit2html(input='example.Rmd', output='example02.html')"
If I run the Makefile file sequentially
make
there is no problem.
If I run the makefile in parallel
make -j 2
the chunks generated by knit2html function overlap and both html files contains the same image.
Any suggestion? I've been searching for a solution but I've found nothing.
Using the idea of Karl, I've written a possible solution.
all : example01.html example02.html
example01.html : example.Rmd
mkdir -p dir_$@
Rscript -e 'library(knitr); opts_knit$$set(base.dir = "dir_$@"); knit2html(input="example.Rmd", output="dir_$@/$@")'
mv dir_$@/$@ .
rm -r dir_$@
example02.html : example.Rmd
mkdir -p dir_$@
Rscript -e 'library(knitr); opts_knit$$set(base.dir = "dir_$@"); knit2html(input="example.Rmd", output="dir_$@/$@")'
mv dir_$@/$@ .
rm -r dir_$@
There are two modifications respect to initial code.
Parallel execution
make -j 2
works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With