gpt4 book ai didi

r - 如何在我呈现的文档之外修改 yaml 指令

转载 作者:行者123 更新时间:2023-12-01 12:03:46 25 4
gpt4 key购买 nike

我要 rmarkdown::render R没有指明 yaml 选项的文档 在文档本身内 .

理想情况下,这可能是 rmarkdown::render 上的一个论点。或 knitr::spin就像你可以做些什么来通过params (见 Rmarkdown reference book)。通常我想要 author , dateoutput选项也是。

我认为这是可能的,因为旋转 following document没有指定任何内容,我得到以下输出(因此必须有一个我希望可以更改的默认参数模板)

enter image description here

例如,我该怎么做 render一个文档会给我与下面说的相同的输出( 但当然没有在文档中指定 yaml ,即文档中没有任何 yaml )

---
title: "Sample Document"
output:
html_document:
toc: true
theme: united
pdf_document:
toc: true
highlight: zenburn
---

#' # Title
Hello world

#+ one_plus_one
1 + 1

最佳答案

您也可以将 yaml 选项作为参数传递。例如:

---
params:
title: "add title"
author: "add author"
output: pdf_document
title: "`r params$title`"
author: "`r params$author`"
---

This is my document text.

然后,在单独的 R 脚本中:
rmarkdown::render("my_doc.rmd", 
params=list(title="My title",
author="eipi10"))

关于r - 如何在我呈现的文档之外修改 yaml 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59699249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com