将原始/未解释的内容添加到 Rmarkdown 文件

Add raw / uninterpreted content to Rmarkdown file

我已经准备了一个包含一些 R 代码的 .Rmd 文件,我在 Rstudio 中将其编织成一个 .md 文件。此 .md 文件将依次被推入 GitHub 存储库,以生成具有特定布局的 GitHub 页面(使用 GitHub pages system)。

我遇到的问题是,当我在我的 Rmarkdown 文件中指定布局时,例如使用以下代码:

---
title: "Untitled"
output: github_document
layout:mylayout
---

它没有出现在 .md 文件中,因此 Github 页面不使用我的布局。要包含我的布局,我需要手动修改 .md 文件以添加以下内容 header:

---
title: "Untitled"
output: 
  html_document
layout:mylayout
---

我不想手动修改我的 .md 文件,即当我将 .Rmd 文件编入 .md 时自动包含上述 header文件。

我尝试了很多方法都没有成功,包括printcatpaste以及用参数results="asis".

写r块代码

是否可以将原始内容放入 .Rmd 中,完全不会被解释?

这是我的 .Rmd 文件的一个非常简单的示例:

---
title: "Untitled"
output: github_document
layout:mylayout
---

# I would like to add the next part at the beginning of my .md file,
# but it is always removed or altered such that it does not appear 'as is' in the .md
---
title: "Untitled"
output: 
  html_document
layout:mylayout
---

# After this header comes the content of the file
Content with R code

GFM 不支持 YAML 元数据,因此 github_document 也不支持。只有 md_document 支持 YAML,例如

---
title: "Untitled"
output:
  md_document:
    variant: markdown_github
    preserve_yaml: true
layout: mylayout
---

但是如果你使用 Jekyll 和 Github 页面,你可以考虑使用 blogdown 而不是单独编写帖子:https://bookdown.org/yihui/blogdown/jekyll.html 那么你就不需要在 YAML 中指定 output 字段。输出将为 .md,并且您的所有 YAML 元数据都将保持不变。