5

It is sometimes desirable to create an R notebook that isn't self-contained. For example, one may want to load Mathjax from a local file of one's choosing, and to do so, self_contained must be FALSE. But I find that, by default, even the simplest R notebooks don't render properly when the YAML header includes self_contained: FALSE. Here is a minimal example:

---
title: "Notebook, not self-contained"
output: 
  html_notebook:
    self_contained: false    
---

Hello.

When this file is rendered with the default rmarkdown::render() options -- or when I "preview" the notebook by saving it in RStudio -- the resulting HTML file doesn't use default R Notebook CSS, and there is a lot of cruft at the top of the file, as shown in this related post. The problem seems to be that, by default, rmarkdown::render() uses clean = TRUE -- and for R notebooks, that means that the external directory containing all the dependencies (jquery, bootstrap, etc.) is destroyed as soon as it is created. For example, if the file above were titled "myNotebook.Rmd," calling rmarkdown::render() with default options would create a myNotebook_files directory that contains the dependencies -- and it would almost instantly delete that directory.

The problem goes away if you call rmarkdown::render() with clean = TRUE. But this solution isn't optimal. It leaves .md files in the output directory that I would like to be removed. And it doesn't work with RStudio shortcuts for knitting or previewing a notebook.

Is there any way to change the default clean = TRUE behavior of rmarkdown::render(), so that it doesn't remove the "_files" directory when self_contained is set to FALSE?

Curiously, this problem arises only when the output format is set to html_notebook -- not when it is set to html_document.

Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
user697473
  • 2,165
  • 1
  • 20
  • 47
  • Although the circumstances are are somewhat different, this sounds [familiar](https://stackoverflow.com/questions/62432329/in-rstudio-where-is-knitr-markdown-output-located/62501835#62501835). Any chance this is a package vignette? – CL. Jul 24 '20 at 13:22
  • No, I found that the problem arose outside of any package-building or vignette-making. It still happens in RStudio 1.3.1056, and it happens whether the project build tools (Tools > Project Options > Build Tools) are set to "none," "package," or "website." But thank you for the "familiar" link -- it does seem relevant. – user697473 Jul 24 '20 at 14:37
  • this just started happening to me, when it was not happening before – Mike M Apr 19 '21 at 01:07
  • 1
    it seems too specific to ignore, so I raised the issue with RMarkdown: https://github.com/rstudio/rmarkdown/issues/2114 – Mike M Apr 19 '21 at 02:28
  • 1
    They actually are not interested in dealing with it, strangely saying that it was never supposed to work - despite being a defined feature for html_notebook - and they don't believe me that it ever did work . . . maybe some political thing going on with managing this recurring problem. At the same time, they did generously provide many workarounds, pointing out that basically all the output features of Notebook are available in html_document today. So if one is not looking for the IDE behaviors like chunk Previews, you basically don't need to use html_notebook at this point. – Mike M Apr 21 '21 at 13:51

0 Answers0