xaringan 动态设置文档标题

问题描述

中是将 title: 移出主 as described in the R Markdown Cookbook 的选项。

但是,在 幻灯片集中,新的 --- 似乎与新幻灯片的想法相冲突。

下面的代码有效,但是当将第 2 行,title: "Presentation Ninja" 移到主 之外,并将其插入为 title: "The name of the dog is r dog_name!",通过删除我所有的<!-- ... --> 第 17-19 行中的代码,它没有按预期工作。我不再得到标题页。我想我需要解决 中的 ---

任何帮助将不胜感激!

---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
  xaringan::moon_reader:
    lib_dir: libs
---
# xaringan set the document title dynamically
       
```{r,code=xfun::read_utf8('script_with_many_dog_names.R')}
```

The name of the dog is `r dog_name`!

<!-- --- -->
<!-- title: "The name of the dog is `r dog_name`!" -->
<!-- --- -->

Some bullets

- Foo

- Bar

解决方法

您可以将逻辑直接添加到标题中,这对我来说似乎很好:

---
title: "The number is `r round(100 * runif(1),2)`"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
  xaringan::moon_reader:
    lib_dir: libs
---

example

,

您可以使用 R Markdown 参数:

  1. 创建模板文件 Template.Rmd
---
title: "The name of the dog is `r params$dog_name`"
subtitle: "⚔<br/>with xaringan"
author: "John Doe"
output:
  xaringan::moon_reader:
    lib_dir: libs
params:
    dog_name: NA
---



# xaringan set the document title dynamically

Some bullets

- Foo

- Bar

  1. 设置dog_name参数后渲染模板:
source('script_with_many_dog_names.R')

# As an example,but it could be the result of previous script
params <- list(dog_name = 'Charles')

rmarkdown::render('Template.Rmd',output_file = 'presentation.html',params = params,envir = new.env(parent = globalenv())
)

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...