问题
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
.
来源:https://stackoverflow.com/questions/60153998/r-notebooks-dont-render-properly-when-self-contained-is-false-because-the-fi