嗨,
我得把数据库记录下来。为此,我想在R标记文件中记录数据库方案。要记录的数据库方案是连接在一起的。
我写了一些函数来完成这项工作。
现在,我唯一要做的就是定义数据库方案。这是一个简单的字符串向量。
在我的文件中,我也使用子标记文件。
问题:
可以对字符串向量的每个元素循环并调用child.rmd吗?
我的{mother.rmd}
---
title: "R Markdown: Loop with child.rmd"
output:
html_document:
df_print: paged
---
```{r}txtvec <- c(“第一”、“第二”、“第三”)
# Is it possible to loop this?
```{r}I <- 1
```{r child="child.rmd"}```{r}I <- 2
```{r child="child.rmd"}```{r}I <- 3
```{r child="child.rmd"}我的{child.rmd} -实际上要复杂得多,包括文本和r块。
## `r txtvec[i]`
Some more text...谢谢你的回答!
发布于 2020-07-21 17:50:56
我认为,包括以下代码块将完成您正在寻找的任务:
```{r results='asis'}
txtvec <- c("first","second","third")
res <- vector(mode = "list", length = 3L)
for (i in 1:3) {
res[[i]] <- knitr::knit_child("child.rmd", quiet = TRUE, envir = environment())
}
cat(unlist(res), sep = '\n')
```注意,在子文档中(据我理解),您必须删除所有块标签,因为否则会重复这些标签。我的答案是基于以下可能也有帮助的文档:https://bookdown.org/yihui/rmarkdown-cookbook/child-document.html
https://stackoverflow.com/questions/63011158
复制相似问题