美文网首页
103.R Markdown中的YAML header

103.R Markdown中的YAML header

作者: 心惊梦醒 | 来源:发表于2022-04-07 08:16 被阅读0次

  YAML是另外一种便于人们读写层次数据的标记语言,R markdown中用它来输出的细节。此处讨论两类:document parameters 和 bibliographies。

文档参数

  正如https://github.com/hadley/r4ds/blob/main/rmarkdown/fuel-economy.Rmd中所看到的,在YAML Header区设置params,可以在下文的代码块中或者文本行中引用对应的参数。

---
output: html_document
params:
  my_class: "suv"
  vectot: 1:5  # 可以是向量
  start: !r lubridate::ymd("2015-01-01")  # 在R 表达式前加!r返回执行表达式后的结果
  snapshot: !r lubridate::ymd_hms("2015-01-01 12:30:00")
---

  https://github.com/hadley/r4ds/blob/main/rmarkdown/fuel-economy.Rmd可作为一个模板,改变my_class的值,结合purrr::pwalk可以输出不同class的报告文件。

# 先将模板保存到本地,然后
reports <- tibble(
  class = unique(mpg$class),
  filename = stringr::str_c("fuel-economy-", class, ".html"),
  params = purrr::map(class, ~ list(my_class = .))
)

reports %>% 
  select(output_file = filename, params) %>% 
  purrr::pwalk(rmarkdown::render, input = "fuel-economy.Rmd")

# rmarkdown::render()函数的功能是将输出呈现为指定格式的输入,指定params可以带参数运行
# 如果有多个class需要分来出报告只需要用不同的参数调用模板即可。
rmarkdown::render("fuel-economy.Rmd", params = list(my_class = "suv"))

Bibliographies 和 Citations,参考文献和引文

  我累了,学不下去了,只贴代码

bibliography: rmarkdown.bib
csl: apa.csl

Separate multiple citations with a `;`: Blah blah [@smith04; @doe99].

You can add arbitrary comments inside the square brackets: 
Blah blah [see @doe99, pp. 33-35; also @smith04, ch. 1].

Remove the square brackets to create an in-text citation: @smith04 
says blah, or @smith04 [p. 33] says blah.

Add a `-` before the citation to suppress the author's name: 
Smith says blah [-@smith04].

相关文章

  • 103.R Markdown中的YAML header

      YAML是另外一种便于人们读写层次数据的标记语言,R markdown中用它来输出的细节。此处讨论两类:doc...

  • markdown 使用介绍

    markdown是什么? markdown优点: markdown常用语法: H1 :# Header 1H2 :...

  • Markdown语法

    常见的Markdown的语法 此文章主要是记录常用的Markdown语法! Header 3 This is a ...

  • 2019-02-11

    MarkDown 基础语法总结 各种header,比如# ,## ,###等等,=====,------多级标题...

  • 2018-07-16

    Markdown基本语法总结 各种header # ## ###,=====,------文字修饰**,_分隔符-...

  • 也学学Markdown

    一点心得 感觉Markdown之于HTML,相当于Json/Yaml之于XML. 虽然Markdown的语法没有H...

  • 开发资料

    通用 MarkDown Git GitFlow Thrift YAML 基础算法 codility强烈建议刷完所有...

  • 从Hello world开始下次

    码农测试第一发,来个Hello world先。 Markdown## Header# wangkui

  • 文档神器mkdocs

    简介 官网:mkdoc.org mkdocs 基于Python,迅速生成基于Markdown和Yaml配置文件生成...

  • MarkDown简单使用

    上面是原始文本,下面是对应Markdown效果,整理出来,方便查阅. A First Level Header A...

网友评论

      本文标题:103.R Markdown中的YAML header

      本文链接:https://www.haomeiwen.com/subject/rrwcsrtx.html