Appendix A: Comments about using Quarto

Here I will collect some notes about using Quarto. At the moment it is just an unordered and unedited collection of all my notes scattered in the chapters. These notes divert the attention from my main goal to learn and understand Bayesian statistics.

A.1 Table excursion

Table Packages Used

Kurz employed the {flextable} package to print tables. As I have no experience with this package, I will apply {kableExtra} in this document.

Until now I had used most of the time kableExtra and sometimes DT. For a short compilation of available table packages see the section on Other packages for creating tables in the R Markdown Cookbook. The following excursion on tables follows the blog article Top 7 Packages for Making Beautiful Tables in R by Devashree Madhugiri.


  • {gt}: The gt package offers a different and easy-to-use set of functions that helps us build display tables from tabular data. The gt philosophy states that a comprehensive collection of table parts can be used to create a broad range of functional tables. These are the table body, the table footer, the spanner column labels, the column labels, and the table header. (I should look into the {gt} package in more detail as it is developed by the RStudio/Posit team, that stands not only for high quality but also for tidyverse compatibility.)

  • {formattable}: Formattable data frames are data frames that will be displayed in HTML tables using formatter functions. This package includes techniques to produce data structures with predefined formatting rules, such that the objects maintain the original data but are formatted. The package consists of several standard formattable objects, including percent, comma, currency, accounting, and scientific.

  • {kableExtra}: It extends the basic functionality of knitr::kable() tables. Although knitr::kable() is simple by design, it has many features missing which are usually available in other packages. {kableExtra} has filled the gap nicely. One of the best thing about {kableExtra} is that most of its table capabilities work for both HTML and PDF formats.

  • {DT}: dt is an abbreviation of ‘DataTables.’ Data objects in R can be rendered as HTML tables using the JavaScript library ‘DataTables’ (typically via R Markdown or Shiny).

  • {flextable}: This package helps you to create reporting table from a data frame easily. You can merge cells, add headers, add footers, change formatting, and set how data in cells is displayed. Table content can also contain mixed types of text and image content. Tables can be embedded from R Markdown documents into HTML, PDF, Word, and PowerPoint documents and can be embedded using Package Officer for Microsoft Word or PowerPoint documents. Tables can also be exported as R plots or graphic files, e.g., png, pdf, and jpeg.

  • {reactable}: reactable() creates a data table from tabular data with sorting and pagination by default. The data table is an HTML widget that can be used in R Markdown documents and Shiny applications or viewed from an R console. It is based on the React Table library and made with reactR. Features are:

    • It creates a data table with sorting, filtering, and pagination
    • It has built-in column formatting
    • It supports custom rendering via R or JavaScript
    • It works seamlessly within R Markdown documents and the Shiny app
  • {ractablefmtr}: The package improves the appearance and formatting of tables created using the reactable R library. It includes many conditional formatters that are highly customizable and easy to use.

I sure there are other packages as well. But the above seven packages are a first starting point to learn creating and displaying sophisticated data tables in R.

The authors of R Markdown Cookbook (Yihui Xie, Christophe Dervieux, Emily Riederer) mention also several other table packages in the section Other packages for creating tables:

I’m not going to introduce the rest of packages, but will just list them here: tables (Murdoch 2023), pander (Daróczi and Tsegelskyi 2022), tangram (S. Garbett 2023), ztable (Moon 2021), and condformat (Oller Moreno 2022).


Quarto cannot list & execute code in the same chunk

2023-05-08: lst-label and lst-cap are only working in display code snippets but not in snippets to execute. See lst-cap and lst-label in Quarto? and lst-label and lst-cap do not produce listing caption and reference.

2023-07-23: In the meanwhile I found a work around:

Listing A.1: R code snippet 2.4: Replicate simulation

Code
#### USE ANOTHER EXAMPLE WITHOUT REFERENCE TO ANOTHER FUNCTION

replicate(sim_globe(p = 0.5, N = 9), n = 10) 

precis() results not printed correctly from visual mode

The result of rethinking::precis() does not display correctly after the chunk in RStudio visual mode. But it works in source mode and it displayed correctly immediately after the chunk.

The columns of the table are too narrow so that you can’t see the header and inspect the values. Printing to the console or to the web is correct.

A workaround is wrapping the result with print() or to render the document in source mode. See my bug report.