我想将一个数据帧转换成一个markdown 表格,以便在html Quarto
中使用.我们可以使用带有md_table
的simplermarkdown
包将数据帧转换为markdown 表格.但问题是,markdown 的输出不会转换为html表格.您可以通过复制输出并将其放入文档来做到这一点,这当然不是自动的.以下是一些可重现的代码:
---
title: "example"
format: html
---
```{r}
library(simplermarkdown)
md_table(head(iris))
```
This is copied from output above:
|Sepal.Length|Sepal.Width|Petal.Length|Petal.Width|Species|
|------------|-----------|------------|-----------|-------|
|5.1 |3.5 |1.4 |0.2 |setosa |
|4.9 |3.0 |1.4 |0.2 |setosa |
|4.7 |3.2 |1.3 |0.2 |setosa |
|4.6 |3.1 |1.5 |0.2 |setosa |
|5.0 |3.6 |1.4 |0.2 |setosa |
|5.4 |3.9 |1.7 |0.4 |setosa |
输出:
如您所见,该函数的输出确实返回了标记格式,但不会自动将其转换为所需的输出(与复制的代码一样).所以我想知道有没有人知道如何将数据帧自动转换成四分音格式的markdown 表格?