{chronicle}

2021-06-24

An R package for easy R Markdown reporting

install.packages('chronicle')

This R package allows the user to create beautiful R Markdown reports in a wide gamut of outputs, without the need to be exposed to the code necessary to create each of its elements. chronicle is built on a layered paradigm, which will be familiar to any ggplot user.

A quick demo

You can build R Markdown reports through the add_* family of functions, layering one below the previous one.

library(chronicle)

demo_report <-
  add_text(text_title = "This is the output of a chronicle call",
           text = "Each element has been added through an add_* function.",
           title_level = 1) %>%
  add_table(table = head(iris),
            table_title = "A glimpse at the iris dataset",
            html_table_type = "kable",
            title_level = 1) %>%
  add_raincloud(dt = iris,
                value = "Sepal.Length",
                groups = "Species",
                raincloud_title = "Distribution of sepal length by species",
                title_level = 2) %>%
  add_scatterplot(dt = iris,
                  x = "Petal.Width",
                  y = "Petal.Length",
                  groups = "Species",
                  scatterplot_title = "Comparison of petal width and length",
                  title_level = 2)

render_report(report = demo_report,
              output_format = "rmdformats",
              filename = "quick_demo",
              title = "A quick chronicle demo",
              author = "You did this!",
              keep_rmd = TRUE)
## Warning: MathJax doesn't work with self_contained when not using the rmarkdown
## "default" template.
## [1] TRUE
## [1] TRUE

You can see the output of this call, and a full showcase of all the elements supported by chronicle.

What happens behind these calls is that chronicle writes an R Markdown for you! you can see the report we’ve built by calling it through cat()

demo_report
## 
## 
## # This is the output of a chronicle call
## 
## Each element has been added through an add_* function.
## 
## # A glimpse at the iris dataset
## ```{r, echo=FALSE, message=FALSE, warning=FALSE}
## knitr::kable(head(iris))
## ```
## 
## ## Distribution of sepal length by species
## ```{r, echo=FALSE, message=FALSE, warning=FALSE, fig.width=params$figure_width, fig.height=params$figure_height}
## chronicle::make_raincloud(dt = iris,
##                           value = 'Sepal.Length',
##                           groups = 'Species',
##                           adjust = 0.5,
##                           include_boxplot = TRUE,
##                           include_mean = FALSE,
##                           include_median = TRUE,
##                           force_all_jitter_obs = FALSE,
##                           ggtheme = 'minimal',
##                           plot_palette = params$plot_palette,
##                           plot_palette_generator = params$plot_palette_generator,
##                           static = params$set_static)
## ```
## 
## ## Comparison of petal width and length
## ```{r, echo=FALSE, message=FALSE, warning=FALSE, fig.width=params$figure_width, fig.height=params$figure_height}
## chronicle::make_scatterplot(dt = iris,
##                             x = 'Petal.Width',
##                             y = 'Petal.Length',
##                             groups = 'Species',
##                             plot_palette = params$plot_palette,
##                             plot_palette_generator = params$plot_palette_generator,
##                             static = params$set_static)
## ```

The make_* family of functions

Every plot added with an add_* function will be built through its correpsonding make_* function. These functions take care of the heavy lifting, avoiding the cumbersome (albeit powerful) sintax of ggplot, plotly and other html widgets. The parameters of the make_functions are simple and intuitive specifications on how to make each plot, and they can be called independently and used in any instance where a ggplot or an html widget would fit.

make_barplot(dt = ggplot2::mpg,
             value = 'cty',
             bars = 'manufacturer',
             break_bars_by = 'drv',
             horizontal = TRUE,
             sort_by_value = TRUE,
             static = TRUE)

chronicle bar plot

make_raincloud(dt = iris,
             value = 'Sepal.Length',
             groups = 'Species')