I am using lists to collect a number of QC plots and tables generated by functions that should be included in a final Rmd markdown html document. The code, as far as I can see, works as expected. All plots and tables are generated and collected. And they are also properly printed in the source window when the whole script is executed.
However, when I knit the document, only the plots are included the way I expect, while the datatables are not. I am not sure why and how to fix this.
Below is a toy example. Apologies for the very long post, but I wanted to show the different behaviors.
Output of individual plot and table in the source window:
library(DT)
plot(cars)
datatable(cars)
Output of plots and tables from lists:
library(DT)
qc_tables <- list()
qc_plots <- list()
qc_plots[[length(qc_plots) + 1]] <- plot(cars)
qc_plots[[length(qc_plots) + 1]] <- plot(iris)
for (p in qc_plots) { print(p) }
qc_tables[[length(qc_tables) + 1]] <- datatable(cars)
qc_tables[[length(qc_tables) + 1]] <- datatable(iris)
for (p in qc_tables) { print(p) }
Screenshot of output in source window:
Now knitting and html output:
---
title: "R Notebook"
output:
html_document
---
# Direct output of plots and Data.Tables
```{r}
library(DT)
plot(cars)
datatable(cars)
plot(iris)
datatable(iris)
```
# Output of plots and Data.Tables from lists
```{r}
library(DT)
qc_tables <- list()
qc_plots <- list()
qc_plots[[length(qc_plots) + 1]] <- plot(cars)
qc_plots[[length(qc_plots) + 1]] <- plot(iris)
for (p in qc_plots) { print(p) }
qc_tables[[length(qc_tables) + 1]] <- datatable(cars)
qc_tables[[length(qc_tables) + 1]] <- datatable(iris)
for (p in qc_tables) { print(p) }
```
Markdown file with direct output:
Markdown output is missing when generating them via a list:
Created on 2021-01-27 by the reprex package (v0.3.0)
question from:
https://stackoverflow.com/questions/65921277/incorporating-dt-tables-into-rmd-markdown-document 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…