Reputation: 7948
In R-markdown there is is an option to move the title:
out of the main YAML, as described in the R Markdown Cookbook.
But, in a Xaringan slide set the new ---
seems to conflict with the idea of new slide.
The below code works, but when move line #2, title: "Presentation Ninja"
outside the main YAML, and inset it as title: "The name of the dog is
r dog_name!"
, by removing all my <!-- ... -->
code in line #17-19, it does not work as expected. I do no longer get a title page. I guess I need to work around the ---
in Xaringan?
---
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
Upvotes: 7
Views: 471
Reputation: 41260
You could use R Markdown
parameters :
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
dog_name
parameter :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())
)
Upvotes: 4
Reputation: 1173
You can add your logic directly to the title, that seems to work fine for me:
---
title: "The number is `r round(100 * runif(1), 2)`"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
output:
xaringan::moon_reader:
lib_dir: libs
---
Upvotes: 3