【发布时间】:2018-07-18 11:10:05
【问题描述】:
编辑
此问题并非(必然)仅与 {htmlTable} 相关。渲染一个使用 {kableExtra} 包 (see also this thread) 设置样式的 html 表格时也会发生同样的情况。
原始问题
我在 RMarkdown 中工作,尝试在循环中使用 htmlTable 包中的 htmltables 呈现文档。当我在 RStudio 中按下“Knit”按钮时,一切正常。但是当我使用render() 函数时,循环中的htmltables 不会被打印,但循环之前的表格会打印。
我看了那个“knit”按钮,渲染功能也是这样,所以我不明白怎么了?
这是带有hmtlTables 的.Rmd 文件的工作示例:
---
output: html_document
---
## htmlTables
```{r, results='asis'}
library(data.table)
library(htmlTable)
library(ggplot2)
a <- data.table(matrix(seq(1, 100, 5), ncol = 2))
htmlTable(a)
for (i in 10:11) {
cat( paste('## title no.', i, '\n' ) )
print(ggplot(a*i, aes(x = V1, y = V2)) + geom_point())
print(htmlTable(a*i))
cat('\n')
}
```
我需要使用不同的参数自动生成许多报告,因此我需要使用 render() 来实现这一点。
【问题讨论】:
-
看起来编织的方式有所不同。
-
问题不仅在于 htmlTable - 它也发生在 kableExtra 样式的 html 表格中(请参阅stackoverflow.com/questions/71052689/…)
标签: html r r-markdown rstudio knitr