Kristofersen
Kristofersen

Reputation: 2806

Remove Markdown Default Code

In RStudio, whenever I make a new Markdown it always has default code. How do I remove it?

Here's the code that shows up.

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

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 cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Upvotes: 2

Views: 2126

Answers (1)

Sixiang.Hu
Sixiang.Hu

Reputation: 1019

Every time, when creating a Rmd file, Rstudio will open a Rmd template:

https://github.com/rstudio/rstudio/blob/822e558c7a274de464f992f69e3acee2fde5ab04/src/cpp/session/modules/SessionRMarkdown.R

# given a path to a folder on disk, return information about the R Markdown
# template in that folder.
.rs.addFunction("getTemplateDetails", function(path) {
   # check for required files
   templateYaml <- file.path(path, "template.yaml")
   skeletonPath <- file.path(path, "skeleton")
   if (!file.exists(templateYaml))
      return(NULL)
   if (!file.exists(file.path(skeletonPath, "skeleton.Rmd")))
      return(NULL)

   # load template details from YAML
   templateDetails <- yaml::yaml.load_file(templateYaml)

   # enforce create_dir if there are multiple files in /skeleton/
   if (length(list.files(skeletonPath)) > 1) 
      templateDetails$create_dir <- TRUE

   templateDetails
})

Hence the simplest solution would be:

  1. go to xxx\RStudio\resources\templates folder, where your Rstudio installed
  2. open r_markdown_v2.Rmd file, and delete everthing
  3. save it

Now, everytime, when you open a rmarkdown, you can have just the yaml part.

Upvotes: 7

Related Questions