Home > other >  Save a list of sjPlot::tab_model tables ta on a word file or a RMarkdown file
Save a list of sjPlot::tab_model tables ta on a word file or a RMarkdown file

Time:11-04

I have this list of tables that I've created by sjPlot

enter image description here

Where every elements contains a table like this

enter image description here

If I would like to create a report with RMarkdown or save them as a word file, would am I supposed to do?

CodePudding user response:

An option is to specify results = 'asis' in the chunk along with using knit_print

---
title: "Title"
output: html_document

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r, echo = FALSE}
suppressPackageStartupMessages(library(sjPlot))
suppressPackageStartupMessages(library(sjmisc))
suppressPackageStartupMessages(library(sjlabelled))
suppressPackageStartupMessages(library(purrr))

# sample data
data("efc")
efc <- as_factor(efc, c161sex, c172code)
```

## R Markdown

```{r data, echo = FALSE}

m1 <- lm(barthtot ~ c160age   c12hour   c161sex   c172code, data = efc)
m2 <- lm(neg_c_7 ~ c160age   c12hour   c161sex   e17age, data = efc)
lst1 <- list(tab_model(m1), tab_model(m2))
```

```{r model out, echo = FALSE, results = 'asis'}
for(i in seq_along(lst1)) cat(knitr::knit_print(lst1[[1]]))
# or use
#iwalk(lst1, ~ cat(knitr::knit_print(.x)))
```

-output

enter image description here

  • Related