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

Time:02-26

I am trying to print my data using the kable function but i cant get it to print in the plots window, i have attached the code i have used underneath if anyone is able to adapt it. If there is a better way to print tables do also let me know please.

mod1:5 are just linear regression models which would be too much to recreate here

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

When i use this code i get what seems to be the formating for the table in the console but no print out;

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

CodePudding user response:

With rmarkdown, specify results = "asis" in the chunk. Below example shows with and without using the option

---
title: "test"
---



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

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

If we want to change the format from printing on 'html', change the argument. According to ?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  |
  • Related