Rendering output of report function from report package to knitr

Viewed 122

I want to render the output of report function from report R package into .Rnw (using knitr) for pdf format output. However, it is not working as expected.

library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
report(model)
We fitted a linear model (estimated using OLS) to predict Sepal.Length with Species (formula: Sepal.Length ~ Species). The model explains a statistically significant and substantial proportion of variance (R2 = 0.62, F(2, 147) = 119.26, p < .001, adj. R2 = 0.61). The model's intercept, corresponding to Species = setosa, is at 5.01 (95% CI [4.86, 5.15], t(147) = 68.76, p < .001). Within this model:

  - The effect of Species [versicolor] is statistically significant and positive (beta = 0.93, 95% CI [0.73, 1.13], t(147) = 9.03, p < .001; Std. beta = 1.12, 95% CI [0.88, 1.37])
  - The effect of Species [virginica] is statistically significant and positive (beta = 1.58, 95% CI [1.38, 1.79], t(147) = 15.37, p < .001; Std. beta = 1.91, 95% CI [1.66, 2.16])

Standardized parameters were obtained by fitting the model on a standardized version of the dataset.

Using report(model) along with results = 'asis' does not work properly since the output contains special character %. Using results = 'markup' does not respect the page width.

I tried kable(report(model)), but throws the following error:

Error in `[<-.data.frame`(`*tmp*`, which, value = "") : 
  unsupported matrix index in replacement

Package Information

packageVersion("report")
[1] ‘0.3.0’

Edited

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\begin{document}

<<include=FALSE>>=
knitr::opts_chunk$set(comment = NA, width = 80)
@

<<chunk1>>=
library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
report(model)
@

\end{document}

Editted (2021-06-22)

It is a bug.

1 Answers

htmltools::tagList() might be what you're looking for:

```{r}
library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
htmltools::tagList(report(model))
```

enter image description here

However, results='asis' seems to better respect line breaks:

```{r,results='asis'}
library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
report(model)
```

enter image description here

Related