2016-02-20 117 views
1

在RStudio中,每当我创建一个新的Markdown时,它总是有默认代码。我如何删除它?删除Markdown默认代码

下面是显示的代码。

```{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. 

回答

5

时,都会创建一个RMD文件时,Rstudio将打开一个RMD模板:

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 
}) 

因此最简单的解决办法是:

  1. xxx\RStudio\resources\templates文件夹,其中您的 Rstudio安装
  2. 开放r_markdown_v2.Rmd文件,并删除 寄托都
  3. 将它保存

现在,每次,当你打开一个rmarkdown,你可以只是YAML部分。

+0

你是最棒的!那太恼人了。谢谢! – Kristofersen