`github_document` removes previously created html files

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.

A somewhat related issue was posted previously here RMarkown PDF Document - Removes other files??

Have you tried updating versions? I think I no longer have the issues with the newest rstudio / all up-to-date packages...

1 Like

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.

Hope it helps understand.

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!

yes please do ! Opening an issue for a feature request to change that would make it visible to others too.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.