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

chunk names must be unique between knitr documents in same directory #875

Closed
v-a-s-a opened this issue Oct 25, 2014 · 5 comments
Closed
Milestone

Comments

@v-a-s-a
Copy link

v-a-s-a commented Oct 25, 2014

This may be a user error/workflow problem rather than an issue with knitr itself, but I was just burned by this.

If you have multiple knitr documents (say Rmarkdown files) in a single directory all chunks producing figures should have unique names between those documents! My workflow consists of writing .Rmd documents, converting those to regular Markdown, and using pandoc to produce a final PDF. From what I can tell, this is a pretty common workflow.

If .Rmd files produce figures with the same chunk name, then only the last figure produced remains in figure/. That means that all subsequent conversions from .md to .pdf reference only one version of a figure. This breaks the tie between the final document, and the code used to generate it.

It may be worth naming files in figure/ in such a way that they are explicitly tied to a report. Not sure what the cleanest solution would be: perhaps appending a short hash of the report file name to the .png file name. Alternatively, you could simple warn users that a file in figure/ already exists with that name and suggest they rename their chunk.

@yihui yihui added this to the v1.8 milestone Oct 25, 2014
@yihui
Copy link
Owner

yihui commented Oct 25, 2014

Thanks for the feedback!

That is exactly what the rmarkdown package does by default. Different .Rmd will use different figure/cache directories. You can also set knitr::opts_chunk$set(fig.path = ???) by yourself.

@yihui yihui closed this as completed Oct 25, 2014
@v-a-s-a
Copy link
Author

v-a-s-a commented Oct 25, 2014

Thank you!

Also: spectacular work on this package. Its been enormously useful, and a lot of fun to use.

@yihui
Copy link
Owner

yihui commented Oct 26, 2014

Thanks for the kind words! :)

@petrelharp
Copy link

I'd vote to re-open this, and take one of @vtrubets suggestions. This is a major gotcha, and just because rmarkdown does it right doesn't mean that knitr doesn't need to: there's good reasons to use knitr without rmarkdown on top of it.

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants