【问题标题】:How to change settings to open an Rmd file without the default script in R?如何更改设置以打开没有 R 中默认脚本的 Rmd 文件?
【发布时间】:2021-03-18 19:35:22
【问题描述】:

有什么方法可以让我在 R 中只使用 yaml 而不是其他所有内容打开 Rmd 文件?

我想要这个...

---
title: "Untitled"
author: ""
date: ""
output: html_document
---

而不是...

---
title: "Untitled"
author: ""
date: ""
output: html_document
---

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

包括地块

您还可以嵌入绘图,例如:

plot(pressure)

请注意,echo = FALSE 参数已添加到代码块中,以防止打印生成绘图的 R 代码。

【问题讨论】:

  • 这样做的目的是什么?目前还不是很清楚您要达到的目标
  • @Bulat 没有什么特别的原因,只是在打开新的 rmd 文件时不得不删除代码有点烦人。
  • 知道了,确实很烦人。我明白你现在想要达到的目标)

标签: r


【解决方案1】:

据我所知,您有两个选择:

1。使用 {rmarkdown::draft()}

您需要在本地保存模板并使用draft() 函数创建一个新文件。

draft(file, template, package = NULL, create_dir = "default", edit = TRUE)

2。使用模板创建一个包并安装该包。

您可以使用您的自定义模板复制和改编dr-harper's 包并在本地安装该包。此选项的好处是允许您从 RStudio 的新文件界面中选择模板。

要创建模板,请关注 Yihui Xie、J.J. Allaire 和 Garrett Grolemund 的 Chapter 17 from R Markdown: The Definitive Guide

【讨论】:

    猜你喜欢
    • 2020-10-08
    • 2011-07-12
    • 2018-04-02
    • 2012-01-09
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    相关资源
    最近更新 更多