If I knit an R Markdown file to html_document, an .html document is created in the same directory, as expected. However, if I then change the output and knit to github_document, the previously created .html file is removed and a new .md file is created. Why does github_document remove previously created files and how can I change this?
Note that if I change back to html_document, the existing .md file will not be removed, so this is working as expected, it is only github_document that removes previous files.
This is because github_document offers a preview mode by creating an html file in addition to the md file. This will overwrite your other html file with the same name. And by default, keep_html is FALSE and that means the html file used for preview is removed from the working dir.
See doc:
This means you can for now:
either set html_preview = FALSE so that no HTML is generated for preview
either set keep_html = TRUE so that the html file used for preview is kept in the working directory
Note that the HTML file generated is aimed at providing a preview like Github rendering - so it is different than html_document rendering.
So currently, unless html_preview = FALSE, you can't have another html file with the same name in your working dir.
If you want to have another workflow, like not having an html file that is the GIthub preview but a html_document format with the same output name, you should open an issue in rmarkdown github repo to explain your case and we thought on a workaround.
Ah I see thank you @cderv for explaining that (and sorry for my late reply)! It sounds like there is no way to keep both for the time being which is what I expected would happen (and that the temporary GH preview file was created in a temp dir as for temporary .nb.html files). If this is something I end use using often in my workflow I will open an issue, thanks for the help!