I've grown tired of repeating the beginning of R Markdown documents over and over again to set up my preferences for knitting and chunk options. An example:
```{r, include=FALSE}
library(tidyverse)
knitr::opts_chunk$set(error = FALSE, message = FALSE,
warning = FALSE, fig.align = 'center')
knitr::opts_knit$set(root.dir = 'DATA/PATH'))
```
If you use this chunk to begin the majority of you .Rmd
files, can you embed this into the .Renviron
or .RProfile
for an R Project? I know you can load libraries via your .RProfile
, and I know knitr::opts_knit$set
also has some sort of integration with options(knitr.package.foo)
in your .RProfile
, but I have been unsuccessful in getting the options()
route to work, and it only accounts for the knitting options, excluding the chunk options. It feels like there should be an easier way to reproduce this, but I can't find any resources exploring it.
The recommended way is to develop a small package that includes it following the steps outlined here: https://rstudio.github.io/rstudio-extensions/rmarkdown_templates.html
Here's an example: https://github.com/rstudio/rticles
As it's bad practice to link-only, here are the steps:
template.yaml
and
skeleton/skeleton.Rmd
template.yaml
will contain the topmatter YAMLskeleton/skeleton.Rmd
will contain your default Rmd.Alternative:
Edit the default files for your Rstudio installation. Depending on your platform they are in something like resources/r_markdown_v2.Rmd
folder of your Rstudio install. But, this will get wiped out anytime you update RStudio.