How to change the Rmarkdown Document template?

Hi,

I would like to change the default Rmarkdown document template file. Whenever I start a new document it contains this text that describes how to build a plot etc.. It was very helpful in the beginning, but now I would much rather have a clean document with prewritten text to load the libraries I always use (e.g., library(tidyverse) and library(here)) and the HTML settings I prefer.

As I understand Chapter 17 in Rmarkdown: the definitive guide I could create a new template. However, that requires building a package, and also I am really looking to change the default document and not to create a new template.

I have been unsuccessful in finding any guides on this.

Is there a way to change the Rmarkdown Document template?

Thanks in advance.

Since RStudio 1.3 you can create document templates for all supported file types.

Create a template in ~/.config/rstudio/templates/default.R (macOS/Linux) or AppData/Roaming/RStudio/templates/default.R (Windows) to try it out. It works with other file types, too; for example creating a file named default.cpp will set the content for new C++ files.

For reference, this is documented in one of the release blog post:

Thank you, @cderv and @andresrcs.

I am now much closer to a solution that I am happy with. However, I am having difficulties changing the default HTML code at the top of new documents. As far as I can see the top HTML part of a new .Rmd document is not dictated by the document.Rmd template file.

To be more specific, I would like my HTML documents to always include these lines at the top

output: html_document
  html_document:
    code_folding: hide

I can add the lines to a document.Rmd template file, and then delete the abundant code in the new document.
E.g., this code at top of my template document.Rmd file

output: html_document
  html_document:
    code_folding: hide
---

Will produce this output in a new document:

---
title: "Untitled"
author: "author"
date: "9/3/2021"
output: html_document
---

output: html_document
  html_document:
    code_folding: hide
---

I can live with deleting the extra lines, but I would be happy to know if there is a way to avoid it.

Thanks again.

This topic was automatically closed 21 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.