forked from insightsengineering/rtables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
162 lines (119 loc) · 6.87 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
output: github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
suppressPackageStartupMessages(library(rtables))
suppressPackageStartupMessages(library(dplyr))
```
# rtables <a href='https://github.com/insightsengineering/rtables'><img src="man/figures/logo.png" align="right" height="200" width="200"/></a>
<!-- start badges -->
[![Check 🛠](https://github.com/insightsengineering/rtables/actions/workflows/check.yaml/badge.svg)](https://github.com/insightsengineering/rtables/actions/workflows/check.yaml)
[![Docs 📚](https://github.com/insightsengineering/rtables/actions/workflows/docs.yaml/badge.svg)](https://insightsengineering.github.io/rtables/)
[![Code Coverage 📔](https://raw.githubusercontent.com/insightsengineering/rtables/_xml_coverage_reports/data/main/badge.svg)](https://raw.githubusercontent.com/insightsengineering/rtables/_xml_coverage_reports/data/main/coverage.xml)
![GitHub forks](https://img.shields.io/github/forks/insightsengineering/rtables?style=social)
![GitHub repo stars](https://img.shields.io/github/stars/insightsengineering/rtables?style=social)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/insightsengineering/rtables)
![GitHub contributors](https://img.shields.io/github/contributors/insightsengineering/rtables)
![GitHub last commit](https://img.shields.io/github/last-commit/insightsengineering/rtables)
![GitHub pull requests](https://img.shields.io/github/issues-pr/insightsengineering/rtables)
![GitHub repo size](https://img.shields.io/github/repo-size/insightsengineering/rtables)
![GitHub language count](https://img.shields.io/github/languages/count/insightsengineering/rtables)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Open Issues](https://img.shields.io/github/issues-raw/insightsengineering/rtables?color=red\&label=open%20issues)](https://github.com/insightsengineering/rtables/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
[![CRAN Version](https://www.r-pkg.org/badges/version/rtables)](https://CRAN.R-project.org/package=rtables)
[![Current Version](https://img.shields.io/github/r-package/v/insightsengineering/rtables/main?color=purple\&label=Development%20Version)](https://github.com/insightsengineering/rtables/tree/main)
<!-- end badges -->
## Reporting tables with R
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:
* cell values and their visualization separate (i.e. no string based tables)
- values need to be programmatically accessible in their non-rounded state for cross-checking
* multiple values displayed within a cell
* flexible tabulation framework
* flexible formatting (cell spans, rounding, alignment, etc.)
* multiple output formats (html, ascii, latex, pdf, xml)
* flexible pagination in both horizontal and vertical directions
* distinguish between name and label in the data structure to work with `CDISC` standards
* title, footnotes, cell cell/row/column references
`rtables` currently covers virtually all of these requirements, and further advances remain under active development.
## Installation
`rtables` is available on CRAN and you can install the latest released version with:
```r
install.packages("rtables")
```
or you can install the latest development version directly from GitHub with:
```r
remotes::install_github("insightsengineering/formatters")
remotes::install_github("insightsengineering/rtables")
```
Note you might need to set your `GITHUB_PAT` environment variable in order to be able to install from GitHub.
Packaged releases (both those on CRAN and those between official CRAN releases) can be
found in the [releases list](https://github.com/insightsengineering/rtables/releases).
## Usage
We first demonstrate with a demographic table-like example and then show the creation of a more complex table.
```{r, message=FALSE}
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)
```
```{r, message=FALSE}
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)
```
# Acknowledgments
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
## Presentations
### Advanced rtables Training
* Part 1 [Slides](https://docs.google.com/presentation/d/1ygQE9UaoXY6C_FiQLkiYtXB_OnkVbXvsMIY6_MQPbx0/edit?usp=sharing)
* Part 2 - Forthcoming
### RinPharma Workshop: Creating Submission-Quality Clinical Trial Reporting Tables in R with rtables
* [Slides](https://docs.google.com/presentation/d/1t0098eh1b8_FaFfRoD7jhP1nxhLmjrJeD5X5MkmKC48)
### R Adoption Series
* [R Adoption Series presentation 2022](https://www.youtube.com/watch?v=1i6vOId2h4A)
* Slides: https://github.com/gmbecker/rtables_radoption_webinar (index.html)
### New (Current) Layouting and Tabulation Framework (v.0.3+)
* [useR!2020 Presentation (on v0.3.1.1) July 2020](https://www.youtube.com/watch?v=CBQzZ8ZhXLA)