Why does bookdown keep the `.md` files with `new_session: yes`?

This is on the order of minor annoyance, but still... curious why after rendering a bookdown book to gitbook format, .md files are kept if the knit-merge option (new_session: yes) is chosen.

I'd rather not keep them since they clutter up the output directory. This is the default behavior for the merge-knit option: the intermediate .md files are deleted unless keep_md: true is specified. I thought the keep_md default might be flipped for knit-merge, but keep_md: false does not have any impact with new_session: yes.

This issue comment suggests this behavior is intended.

Probably overkill since this appears intentional, but in case it helps, here is a MWE showing that the .md files are kept with new_session: true: https://minimumexample.github.io/keepmarkdownfalse/

Explanation

This does appear to be a result of new_session which in turns uses render_new_session() that ends up generating a bunch of .md files. Those .md files are what's being passed to render(), so specifying the clean option there won't remove the files, because they're the original from the perspective of this call.

It appears differentiating between which files were originally .md and which were .Rmd rendered to markdown is difficult at that point in the execution.

Desired behavior

Does the following describe the desired behavior when keep_md: false is specified in _output.yml and new_session: yes in _bookdown.yml:

  1. The .md corresponding to chapter .Rmd files should be removed.
  2. Chapter files originally .md, it should be preserved.

I think that can be accomplished in the bookdown package. Perhaps put in a feature request?

Band Aid

For the current setup it appears to be on you to all the .md files from your docs directory. If you're calling render_book from a script, you could add a line after the call

unlink(list.files('docs', '\\.md$', full.names = T))

If you're building this using the Rstudio button... dunno yet. I'll come back to this if I come up with an approach less involved that writing and add-in to do it.

Minimal Example Github Organization

Did you really create a github organization called 'minimalexample' just to post the gist? If so, I'm entertained.

3 Likes

Thanks, good to know that there's a reason for it. Yes, that is the desired behavior though I'll save my feature requests for more important items. And yes, I did create an org for this and future MWEs. In the past, I accidentally deleted a few repos that were linked to SO questions and have a bunch more that I'm not sure if I can delete or not so attempting to separate these examples from my other work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.