r语言 - 为什么 YAML 中的 Rmarkdown 动态标题没有出现在 pdf 文件中



我正在尝试从具有动态标题的Rmarkdown生成动态PDF报告。为此,我在 R 脚本中使用函数 rmarkdown::render(),并将标题参数params参数传递为 set.title = title

我的Rmarkdown脚本的 YAML 我有下一个代码:

author: "Author test"
date: "`r Sys.setlocale('LC_TIME','C');format(Sys.Date(),'%B %d, %Y')`"
output:
  pdf_document:
    toc: yes
    toc_depth: 5
    keep_tex: yes
  html_document:
    theme: united
    toc: yes
classoption: table
header-includes:
  - usepackage{array}
  - usepackage{float}
  - usepackage{xcolor}
  - usepackage{caption}
  - usepackage{longtable}
  #- usepackage{mulicol}
params: 
  set.title: title
title: "`r params$set.title`"

一旦我运行了我的代码,一切顺利并生成了我期望的不同 pdf,问题是这些 PDF 都没有显示标题作者日期。我正在使用rmarkdown软件包的 1.8 版。

任何人都可以帮助我解决这个问题吗?

为了结束这个问题的对话,我写了如何解决这个问题。一开始,我认为这个问题与 YAML 中的代码有关(其中标题是从参数通知的),但最终我发现没有什么可以做的。问题是我在作为参数传递的可变标题中使用了函数cat(),并且该函数将变量标题的值更改为NULL

要确切地了解有关如何在 rmarkdown 文档中编写动态标题的所有说明,请将您重定向到下一个入口:从参数在 Rmarkdown 中设置文档标题

最新更新