Skip to content

render_book() should not touch the source .Rmd files #405

@clauswilke

Description

@clauswilke

First thanks a lot for the fantastic work you're doing with knitr and bookdown!

I have the following concern: I have noticed that bookdown::render_book() touches the .Rmd source files. I'm using the knit-then-merge approach and I'm using a before-chapter script, just like Hadley does in his r4ds book. What appears to be happening is that the before-chapter script is actually inserted into the source .Rmd file, then the file is knitted, and then the original source file is restored. This problematic for at least two reasons:

  1. Most importantly, I've had several instances when the before-chapter script was not properly removed from the source file. I'm not sure exactly when this happens, but it could be a race condition between render_book() and my editor, i.e., render_book() changes the file, my editor picks it up, then I modify the file in my editor before render_book() restores it, and I end up with a source file that contains the before-chapter script.

  2. More generally, though, I don't think any compilation process should touch source files at all. It messes up time stamps, and it risks corruption of the original source if anything goes wrong, e.g. the compile crashes, the power goes out, whatever.

The correct approach would be to copy the source file into a temporary file, modify the temporary file, knit that, and then delete.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions