:scroll: :tada: Automated reporting of objects in R
knitr::opts_chunk$set(
collapse = TRUE,
dpi = 300,
fig.path = "man/figures/",
comment = "#",
message = FALSE,
warning = FALSE
)
options(
knitr.kable.NA = "",
digits = 4,
width = 80
)
library(dplyr)
library(report)
“From R to your manuscript”
report’s primary goal is to bridge the gap between R’s output and the formatted results contained in your manuscript. It automatically produces reports of models and data frames according to best practices guidelines (e.g., APA’s style), ensuring standardization and quality in results reporting.
library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
report(model)
The package is available on CRAN
and can be downloaded by running:
install.packages("report")
If you would instead like to experiment with the development version, you can
download it from GitHub
:
install.packages("remotes")
remotes::install_github("easystats/report") # You only need to do that once
Load the package every time you start R
library("report")
Tip
Instead of
library(report)
, uselibrary(easystats)
.
This will make all features of the easystats-ecosystem available.To stay updated, use
easystats::install_latest()
.
The package documentation can be found here.
The report
package works in a two step fashion. First, you create a report
object with the report()
function. Then, this report object can be displayed either textually (the default output) or as a table, using as.data.frame()
. Moreover, you can also access a more digest and compact version of the report using summary()
on the report object.
The report()
function works on a variety of models, as well as other objects such as dataframes:
report(iris)
print(report(iris), width = 80)
These reports nicely work within the tidyverse workflow:
iris %>%
select(-starts_with("Sepal")) %>%
group_by(Species) %>%
report() %>%
summary()
iris %>%
select(-starts_with("Sepal")) %>%
group_by(Species) %>%
report() %>%
summary() %>%
print(width = 80)
Reports can be used to automatically format tests like t-tests or correlations.
report(t.test(mtcars$mpg ~ mtcars$am))
t.test(mtcars$mpg ~ mtcars$am) %>%
report() %>%
print(width = 80)
As mentioned, you can also create tables with the as.data.frame()
functions, like for example with this correlation test:
cor.test(iris$Sepal.Length, iris$Sepal.Width) %>%
report() %>%
as.data.frame()
This works great with ANOVAs, as it includes effect sizes and their interpretation.
aov(Sepal.Length ~ Species, data = iris) %>%
report()
aov(Sepal.Length ~ Species, data = iris) %>%
report() %>%
print(width = 80)
Reports are also compatible with GLMs, such as this logistic regression:
model <- glm(vs ~ mpg * drat, data = mtcars, family = "binomial")
report(model)
glm(vs ~ mpg * drat, data = mtcars, family = "binomial") %>%
report() %>%
print(width = 80)
Mixed models, whose popularity and usage is exploding, can also be reported:
library(lme4)
model <- lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
report(model)
library(lme4)
lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris) %>%
report() %>%
print(width = 80)
Bayesian models can also be reported using the new SEXIT framework, which combines clarity, precision and usefulness.
library(rstanarm)
model <- stan_glm(mpg ~ qsec + wt, data = mtcars)
report(model)
options(mc.cores = parallel::detectCores())
library(rstanarm)
model <- stan_glm(mpg ~ qsec + wt, data = mtcars, refresh = 0, iter = 1000) %>%
report() %>%
print(width = 80)
One can, for complex reports, directly access the pieces of the reports:
model <- lm(Sepal.Length ~ Species, data = iris)
report_model(model)
report_performance(model)
report_statistics(model)
This can be useful to complete the Participants paragraph of your manuscript.
data <- data.frame(
"Age" = c(22, 23, 54, 21),
"Sex" = c("F", "F", "M", "M")
)
paste(
report_participants(data, spell_n = TRUE),
"were recruited in the study by means of torture and coercion."
)
data <- data.frame(
"Age" = c(22, 23, 54, 21),
"Sex" = c("F", "F", "M", "M")
)
paste(
report_participants(data, spell_n = TRUE),
"were recruited in the study by means of torture and coercion."
) |>
insight::format_message() %>%
cat()
Report can also help you create a sample description table (also referred to as Table 1).
report_sample(iris, by = "Species")
knitr::kable(report_sample(iris, by = "Species"))
Finally, report includes some functions to help you write the data analysis paragraph about the tools used.
report(sessionInfo())
report(sessionInfo()) %>%
print(width = 80)
If you like it, you can put a star on this repo, and cite the package as follows:
citation("report")
report is a young package in need of affection. You can easily be a part of the developing community of this open-source software and improve science! Don’t be shy, try to code and submit a pull request (See the contributing guide). Even if it’s not perfect, we will help you make it great!
Please note that the report project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.