Rmarkdown websites better practices for the output_dir: _site or "."

Dear community,

When building Rmarkdown websites, I see there are two common options for the output_dir: a folder _site or "." the root directory.

Is there any advantage of one over the other one?


1 Like

It's personal preference. Do you want the HTML files (and other supporting website files) to be in a separate directory or right next the Rmd files? I personally prefer to keep the HTML files in a separate directory so that it is less cluttered.

One potential use case where the decision matters is hosting your website with GitHub Pages. There are multiple options for where to save your website files. If you choose gh-pages or master branch, then the HTML files need to be in the root of the project (output_dir: "."). If you choose the master branch docs/ folder, then the HTML files need to be in a subdirectory named docs/ (output_dir: "docs/").


Thank you very much. It was very helpful. Just one more question that may be is not completely related to R and following your suggestion. Choosing a master branch docs/ will be similar to have a _site folder but with the difference that the first option it will allow me to publish my website through Github?

1 Like

Right. If you change output_dir to docs/, build and commit the docs/ folder, push to GitHub, and then activate GitHub Pages via "master branch docs/ folder", then your website will be hosted for free. Please let me know if you run into any difficulties getting this to work.

1 Like

I created the docs folder in Github, I set the output_dir: "docs" in the _site.yml, but I cannot publish my website. Any idea why?

It did work. I think it was a matter of time. Thank you very much John.

1 Like

It can occasionally take awhile for the site to first launch. I think it's reasonable for a free service, and subsequent updates will build much faster. One trick I've used in the past is to explicitly request the index.html page in the URL. This is sometimes available before the standard URL is.

Since your question has been answered, could you please choose a solution for the benefit of future readers of this thread?

FAQ: How do I mark a solution?

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