gpt4 book ai didi

r - 循环中的 knit_child - 变量作为标题

转载 作者:行者123 更新时间:2023-12-02 03:56:04 25 4
gpt4 key购买 nike

正在关注 thisthis stackoverflow-questions,我尝试在循环中使用 knit-child,其中包含一个变量定义的标题。

我得到的不是变量(例如 A、B、C)作为标题,而是带有 # 的变量(#A、#B、#C)

家长:

---
title: "Untitled"
output: html_document
---

```{r,include=FALSE}
library(knitr)
```


```{r,echo=FALSE}

titles<-LETTERS[1:3]

```

```{r,include=FALSE,echo=FALSE}
out = NULL
for (i in titles){
out = c(out, knit_child('Child.Rmd'))
}
```


`r paste(out, collapse='\n')`

child :

---
title: "Untitled"

output: html_document
---


```{r,echo=FALSE,results='asis'}

cat("\n\n # ", i,"\n")

```

```{r,echo=FALSE,results='asis'}

cat("\n\n This text is about ", i,"\n")

```

输出:

enter image description here

虽然我更愿意:

enter image description here

最佳答案

如果 # 字符是行的第一个字符,则它仅表示 markdown 中的标题。

cat("\n\n # ", i,"\n") 生成两个新行,然后是一个空格,然后 #。删除空格以解决问题:

cat("\n\n# ", i,"\n")

关于r - 循环中的 knit_child - 变量作为标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43873345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com