我准备了一个带有一些R代码的.Rmd
文件,我在Rstudio中将其编织成一个.md
文件。这个.md
文件将被推送到GitHub存储库中,以便生成具有特定布局的GitHub页面(使用GitHub pages系统(。
我遇到的问题是,当我在Rmarkdown文件中指定布局时,例如使用以下代码:
---
title: "Untitled"
output: github_document
layout:mylayout
---
它没有出现在.md
文件中,因此Github页面不使用我的布局。为了包括我的布局,我需要手动修改.md
文件以添加以下标题:
---
title: "Untitled"
output:
html_document
layout:mylayout
---
我不想手动修改我的.md
文件,也就是说,当我将.Rmd
文件编织成.md
文件时,自动包含上述标头。
我尝试了许多方法,包括print
、cat
、paste
,以及用参数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元数据将保持不变。