如何使用 kable 在绘图 window(或降价)中打印表格?

How can I print tables in the plot window (or markdown) using kable?

我正在尝试使用 kable 函数打印我的数据,但我无法在绘图中打印它 window,如果有人能够修改它,我已经附上了我在下面使用的代码。如果有更好的打印方式 tables 也请告诉我。

mod1:5 只是线性回归模型,在这里重新创建太多了

 mod_comparason = compare_performance(mod1, mod2, mod3, mod4, mod5) 
 #print this data in a table
 print(kable(mod_comparason))

当我使用这段代码时,我得到的似乎是控制台中 table 的格式,但没有打印出来;

<table>
<thead>
<tr>
<th style="text-align:left;"> Name </th>
<th style="text-align:left;"> Model </th>
<th style="text-align:right;"> AIC </th>
<th style="text-align:right;"> AIC_wt </th>
<th style="text-align:right;"> BIC </th>
<th style="text-align:right;"> BIC_wt </th>
<th style="text-align:right;"> RMSE </th>
<th style="text-align:right;"> Sigma </th>
<th style="text-align:right;"> R2 </th>
<th style="text-align:right;"> R2_adjusted </th>
<th style="text-align:right;"> R2_conditional </th>
<th style="text-align:right;"> R2_marginal </th>
<th style="text-align:right;"> ICC </th>

rmarkdown一起,在块中指定results = "asis"。下面的示例显示了使用和不使用选项

---
title: "test"
---



```{r, echo = FALSE}
library(kableExtra)
print(kable(head(mtcars)))
```

```{r, results = "asis", echo = FALSE}
library(kableExtra)
print(kable(head(mtcars)))
```

如果我们想改变 format 在 'html' 上打印,请更改参数。根据?kable

format - A character string. Possible values are latex, html, pipe (Pandoc's pipe tables), simple (Pandoc's simple tables), and rst. The value of this argument will be automatically determined if the function is called within a knitr document. The format value can also be set in the global option knitr.table.format. If format is a function, it must return a character string.

kable(head(iris), "pipe")

| 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  |