变量作为rmarkdown中的标题 [英] Variable as title in rmarkdown

查看:316
本文介绍了变量作为rmarkdown中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简而言之:如何在rmarkdown中的块内打印html头(使用变量在代码块内创建头)?

In short: how can I print a html-header inside a chunk in rmarkdown (use a variable to create a header inside a code-chunk)?

很久:

假设我的数据集中有多个变量(名称也存储在向量"Vars"中),每组3个变量都属于同一主题.

Let's say I have a number of variables in my dataset (names also stored in the vector 'Vars'), and each group of 3 variables belongs to the same subject.

我可以循环绘制所有变量,但我希望标题中包含该主题.像这样:

I can make a loop to plot all the variables, but I want the subject in a title. Something like:

绘制Var1

绘制Var2

绘制Var3

绘制变量4

绘制变量5

...

下面的伪代码有望解释我想要做什么:

Following pseudo-code hopefully explains what I want to do:

```{r}

for (i in Vars)

    if(i%%3 == 1){
        print(## Subject[ceiling(i/3)])}

    plot(i)


```

推荐答案

  • 不要使用印刷品,它会添加装饰性的东西.
  • 请注意必填的双"\ n";仅检查一个会发生什么,因此当您下次忘记它时就做好了准备
  • ```{r, results="asis", echo = FALSE}
    i = 1
    cat("## Subject", i, "\n")
    plot(i)
    i = 2
    cat("\n\n## Subject", i, "\n")
    plot(i)
    ```
    

    这篇关于变量作为rmarkdown中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆