'R Markdown Template Creation
So I am just curious if anybody knows how to change the default R Markdown Creation file with the following output:
---
title: "Untitled"
author: "Cody Glickman"
date: "February 27, 2016"
output: html_document
---
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
You can also embed plots, for example:
```{r, echo=FALSE}
plot(cars)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
When I create new R Markdown documents it would be a nice shortcut to avoid deleting this chunk and inserting a table of contents everytime.
Solution 1:[1]
You can define your own templates, and then create new document using From Template in RStudio. See http://rmarkdown.rstudio.com/developer_document_templates.html
Solution 2:[2]
You can see this page for more details, but basically you just need to create a template.yaml file with an attached Rmarkdown template and put it in the right folder (inst/rmarkdown/templates). You can either create this from the menu in Rstudio "from template" or rmarkdown::draft("my_article.Rmd", template = "jss_article", package = "rticles").
Solution 3:[3]
The useful usethis package has a nice utility function for creating R Markdown templates.
library(usethis)
use_rmarkdown_template(
template_name = "Template Name",
template_dir = NULL,
template_description = "A description of the template",
template_create_dir = FALSE
)
Using this creates:
inst/rmarkdown/templates/{{template_dir}}. Main directory.skeleton/skeleton.Rmd. Your template Rmd file.template.ymlwith basic information filled in.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xiongbing Jin |
| Solution 2 | Chris C |
| Solution 3 | slhck |
