【问题标题】:xaringan set the document title dynamicallyxaringan 动态设置文档标题
【发布时间】:2021-05-24 12:00:07
【问题描述】:

中是一个将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

【问题讨论】:

    标签: r-markdown yaml xaringan yaml xaringan r dynamic r-markdown slideshow xaringan


    【解决方案1】:

    你可以使用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())
    )
    

    【讨论】:

    • 有趣的解决方法,谢谢。然而,它确实使情况复杂了一点,它可以工作。谢谢。
    • 感谢您的反馈。我添加了您自己的脚本采购的可能实现。参数可以是使上述结构高度可定制的任何列表。也没有找到直接修改 YAML 的方法。
    【解决方案2】:

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

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

    【讨论】:

    • 感谢您回答我的问题!我意识到应该提到我需要使用我正在采购的外部变量。对不起!你确实有投票权:)
    • 明白了,抱歉我最初没有关注。没想到你能做到这一点,太酷了!我可以确认这似乎适用于我正在测试的其他输出,包括 Powerpoint,但不适用于 xaringan 模板。我想我们需要这个人自己一辉来做这个。我知道他经历了所有用 xaringan 和他制作的其他软件包标记的问题,但也许值得在 GitHub 上提出问题!很乐意根据需要提供帮助!
    猜你喜欢
    • 2012-12-11
    • 2012-01-30
    • 2014-06-04
    • 1970-01-01
    • 1970-01-01
    • 2015-11-14
    • 2021-12-29
    • 2014-02-19
    • 2019-01-18
    相关资源
    最近更新 更多