Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallel render()'s with different output_file's overwrite each other #499

Open
petrelharp opened this issue Aug 17, 2015 · 6 comments
Open
Labels
bug an unexpected problem or unintended behavior theme: render function related to rendering documents

Comments

@petrelharp
Copy link

I commonly write .Rmd templates, that then get rendered to create a report with different input parameters. However, if more than one such job is being rendered at the same time, since the name of the intermediate .md file is based on the input, all jobs write to the same intermediate.

The result is that I (silently) get wrong reports.

Here is a MWE.

test.Rmd:

I am writing to `r outname`.html.

test.sh:

#!/bin/bash
R --vanilla -e "outname=\"${1}\";require(rmarkdown);render(\"test.Rmd\",output_file=\"${1}.html\")"

Run two at the same time:

for x in one two; do (./test.sh $x &); done
grep "writing to" *.html
# one.html:<p>I am writing to two.html.</p>
# two.html:<p>I am writing to two.html.</p>

Non-workarounds:

  • "specify intermediates_dir", but if there's images in the document this fails (render with intermediates_dir fails with images #500)
  • "first render to md_document, then render to html", but the same problem occurs because render actually outputs to input.utf8.md, with no chance to change this

A fix?

It seems better to use tempfile(), e.g.

 knit_output <- intermediates_loc(tempfile(tmpdir=".",fileext=".knit.md"))

... at least when output_file is specified.

@petrelharp
Copy link
Author

Additional non-workaround: knit_root_dir. Revised test.sh:

#!/bin/bash
R --vanilla -e "outname=\"${1}\";require(rmarkdown);render(\"test.Rmd\",output_file=\"${1}.html\",knit_root_dir=dirname(\"${1}\"))"

and running has the same problem.

for x in a/one b/two; do (mkdir $(dirname $x); ./test.sh $x &); done
grep "writing to" */*.html
# a/one.html:<p>I am writing to b/two.html.</p>
# b/two.html:<p>I am writing to b/two.html.</p>

@Pablo-Leon
Copy link

Hitting this problem too!

how do I up-vote the issue?

@yihui yihui added this to the v1.8 milestone Oct 17, 2017
@yihui yihui modified the milestones: v1.8, v1.9 Nov 15, 2017
@yihui yihui modified the milestones: v1.9, v1.10 Mar 4, 2018
@yihui yihui modified the milestones: v1.10, v1.11 Jun 15, 2018
@rich-iannone rich-iannone added bug an unexpected problem or unintended behavior Difficulty: Intermediate labels Jun 19, 2018
@yihui yihui removed this from the v1.11 milestone Jun 25, 2018
@darth-donut
Copy link

Is there a temporary solution to this problem?

@petrelharp
Copy link
Author

I use my own package to avoid this problem: https://github.com/petrelharp/templater

If it's useful but you hit snags, please let me know over there.

@darth-donut
Copy link

I'll give it a go and let you know if I hit a snag, cheers!

@cderv cderv added the theme: render function related to rendering documents label Jan 12, 2022
@JTC-R
Copy link

JTC-R commented Jul 21, 2022

I also have this issue; I run a parallel report generation that consists of over 1,000 reports. Often times reports will be "mis-matched" where the title of the report will contain the wrong information from a different report.

Setting the intermediates_dir param in an effort to over-come this fails as the doing so provokes its own bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior theme: render function related to rendering documents
Projects
None yet
Development

No branches or pull requests

7 participants