knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" ) suppressPackageStartupMessages(library(rtables)) suppressPackageStartupMessages(library(dplyr))
The rtables
R package was designed to create and display complex tables with R. The cells in an rtable
may contain
any high-dimensional data structure which can then be displayed with cell-specific formatting instructions. Currently,
rtables
can be outputted in ascii
html
, and pdf
, as well Power Point (via conversion to flextable
objects). rtf
support is in development and will be in a future release.
rtables
is developed and copy written by F. Hoffmann-La Roche
and it is released open source under Apache
License Version 2.
rtables
development is driven by the need to create regulatory ready tables for health authority review. Some of the key requirements for this undertaking are listed below:
CDISC
standardsrtables
currently covers virtually all of these requirements, and further advances remain under active development.
rtables
is available on CRAN and you can install the latest released version with:
install.packages("rtables")
or you can install the latest development version directly from GitHub with:
# install.packages("pak") pak::pak("insightsengineering/rtables")
Packaged releases (both those on CRAN and those between official CRAN releases) can be found in the releases list.
To understand how to use this package, please refer to the Introduction to rtables
article, which provides multiple examples of code implementation.
We first demonstrate with a demographic table-like example and then show the creation of a more complex table.
library(rtables) lyt <- basic_table() %>% split_cols_by("ARM") %>% analyze(c("AGE", "BMRKR1", "BMRKR2"), function(x, ...) { if (is.numeric(x)) { in_rows( "Mean (sd)" = c(mean(x), sd(x)), "Median" = median(x), "Min - Max" = range(x), .formats = c("xx.xx (xx.xx)", "xx.xx", "xx.xx - xx.xx") ) } else if (is.factor(x) || is.character(x)) { in_rows(.list = list_wrap_x(table)(x)) } else { stop("type not supported") } }) build_table(lyt, ex_adsl)
library(rtables) library(dplyr) ## for simplicity grab non-sparse subset ADSL <- ex_adsl %>% filter(RACE %in% levels(RACE)[1:3]) biomarker_ave <- function(x, ...) { val <- if (length(x) > 0) round(mean(x), 2) else "no data" in_rows( "Biomarker 1 (mean)" = rcell(val) ) } basic_table(show_colcounts = TRUE) %>% split_cols_by("ARM") %>% split_cols_by("BMRKR2") %>% split_rows_by("RACE", split_fun = trim_levels_in_group("SEX")) %>% split_rows_by("SEX") %>% summarize_row_groups() %>% analyze("BMRKR1", biomarker_ave) %>% build_table(ADSL)
We would like to thank everyone who has made rtables
a better project by providing feedback and improving examples & vignettes. The following list of contributors is alphabetical:
Maximo Carreras, Francois Collins, Saibah Chohan, Tadeusz Lewandowski, Nick Paszty, Nina Qi, Jana Stoilova, Heng Wang, Godwin Yung
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.