4
votes

In RStudio, I set the knit option to current folder :
see knitr option

When I knit a Markdown document to HTML, this surprisingly happens in a temporary directory (for example : 'Temp\RtmpOa3xSM\preview-11e8c6644fdd.dir' directory).

As far as I can remember, this didn't happen previously : the knit would happen in the directory I selected in the options.

Option rstudio.markdownToHTML isn't set :

getOption('rstudio.markdownToHTML')
NULL

When I close the HTML preview, the HTML document disappears.

The only solution I found to keep the HTML document is to open the document in a Browser and to save it from there.

Bug or am I missing something? Thanks for your help!

[EDIT] other Win 10 users reported to me the same problem

1
Interesting - I cannot reproduce this. Just updated to RStudio 1.3.959 and R4.0.1 (on Win10): The "Knit Directory" is respected and the HTML file is created next to the RMD file. The HTML file is not deleted when I close the preview. Is there something weird about the name of your RMD file or the directory where it is located?CL.
@CL, thanks for your feedback. Important to know it's not a generalized bug. Nothing particular about the file name, happens unfortunately with any .RmdWaldi
Can you add some details - what exactly is happening? I guess: 1) You create (save) a minimal RMD file yourfile.Rmd. 2) You hit the knit button. 3) The preview opens and displays your HTML file. At this point, your file explorer displays yourfile.html next to yourfile.Rmd. (Or does it only exist in the temporary directory?) 4) You close the preview and the HTML file vanishes. \\ Is that correct? What does the RMarkdown log say?CL.
Possibly related: stackoverflow.com/q/58955908/2706569 And maybe even this: stackoverflow.com/q/48774057/2706569 Are you in an RStudio Project?CL.
@CL, thanks for your feedback! I think your second link explains exactly what happens when I do what you described in your previous comment. I was in the vignette folder of a package... To avoid cluttering RStudio deletes the HTML here, didn't know about this! Can you please write down the answer so that I can close the question?Waldi

1 Answers

8
votes

Under certain conditions, RStudio moves the knitted (HTML or PDF) file to a temporary directory (located under tempdir()). These conditions are:

  • You are in a RStudio Project.
  • The "Project build tools" are set to "Package".
  • The RMD file is located in a subdirectory vignettes.
  • Knitting is initiated with the "Knit" button in RStudio.

Typically, this happens when knitting a package vignette and has the purpose of "keep[ing] your vignettes folder from becoming cluttered with HTML files".

Changing the Project build tools, changing the folder name or closing the project prevents this behavior. Another way to keep the generated (HTML or PDF) file is to call rmarkdown::render interactively (although this is not exactly equivalent to the "Knit" button).

Note that this only affects where the generated file will be saved. The Working Directory while knitting is unaffected.