https://github.com/insightsengineering/rtables.officer
Reporting tables with R, with officeR support
https://github.com/insightsengineering/rtables.officer
pharmaceuticals r tables
Last synced: 5 months ago
JSON representation
Reporting tables with R, with officeR support
- Host: GitHub
- URL: https://github.com/insightsengineering/rtables.officer
- Owner: insightsengineering
- License: other
- Created: 2024-10-16T22:40:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-12-31T06:01:08.000Z (5 months ago)
- Last Synced: 2026-01-04T03:42:33.439Z (5 months ago)
- Topics: pharmaceuticals, r, tables
- Language: R
- Homepage: https://insightsengineering.github.io/rtables.officer/
- Size: 18.8 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
---
output: github_document
editor_options:
chunk_output_type: console
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
suppressPackageStartupMessages(library(rtables.officer))
suppressPackageStartupMessages(library(dplyr))
```
[](https://github.com/insightsengineering/rtables.officer/actions/workflows/check.yaml)
[](https://insightsengineering.github.io/rtables.officer/)
[](https://raw.githubusercontent.com/insightsengineering/rtables.officer/_xml_coverage_reports/data/main/coverage.xml)








[](https://www.repostatus.org/#active)
[](https://github.com/insightsengineering/rtables.officer/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)
[](https://github.com/insightsengineering/rtables.officer/tree/main)
## Exporting `rtables` to Microsoft Word and beyond
The `rtables.officer` package provides a framework to export tables created with
[`rtables`](https://github.com/insightsengineering/rtables/) to Microsoft Word documents. To do so,
we use the `officer` package to create a Word document and the `flextable` package to produce
the intermediary table object that `officer` can use to create the Word document.
Please refer to the following packages for further information:
- [`rtables`](https://github.com/insightsengineering/rtables/) to create tables.
- [`flextable`](https://github.com/davidgohel/flextable) as an intermediate html table object. Many
aesthetic functionalities are available at this stage.
- [`officer`](https://github.com/davidgohel/officer) to create Word documents. Please consider
also other exporter options (e.g. `html`) that are available from `flextable`.
`rtables` and `rtables.officer` is developed and copy written by `F. Hoffmann-La Roche` and it is released open source under Apache License Version 2.
## Installation
`rtables.officer` is available on CRAN and you can install the latest released version with:
```r
install.packages("rtables.officer")
```
or you can install the latest development version directly from GitHub with:
```r
# install.packages("pak")
pak::pak("insightsengineering/rtables.officer")
```
## Example
Here's a simple example demonstrating how to create a basic table layout, perform analysis on various columns, and export the resultant table to a Word document in landscape orientation. Further reading are available in the [vignettes](https://insightsengineering.github.io/rtables.officer/latest-tag/articles/).
```{r}
# Define the table layout
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
analyze(c("AGE", "BMRKR2", "COUNTRY"))
# Build the table
tbl <- build_table(lyt, ex_adsl)
# Export the table to a Word document in landscape orientation
tf <- tempfile(fileext = ".docx")
export_as_docx(tbl,
file = tf,
section_properties = section_properties_default(orientation = "landscape")
)
# Expected output (with default theme)
tt_to_flextable(tbl, theme = theme_docx_default())
```
## Contributions
To contribute to this package, please fork the repository, create a branch, make your changes, and submit a pull request. Your contributions are greatly appreciated!
