Title: | Clinical Trial Style Data Readout Listings |
Version: | 0.2.12 |
Date: | 2025-05-28 |
Description: | Listings are often part of the submission of clinical trial data in regulatory settings. We provide a framework for the specific formatting features often used when displaying large datasets in that context. |
License: | Apache License 2.0 |
URL: | https://insightsengineering.github.io/rlistings/, https://github.com/insightsengineering/rlistings/ |
BugReports: | https://github.com/insightsengineering/rlistings/issues |
Depends: | formatters (≥ 0.5.11), methods, tibble (≥ 2.0.0) |
Imports: | checkmate (≥ 2.1.0), grDevices, grid, stats, utils |
Suggests: | dplyr (≥ 1.0.2), knitr (≥ 1.42), lifecycle (≥ 0.2.0), rmarkdown (≥ 2.23), stringi (≥ 1.6), testthat (≥ 3.1.5), withr (≥ 2.0.0) |
VignetteBuilder: | knitr, rmarkdown |
Config/Needs/verdepcheck: | insightsengineering/formatters, tidyverse/tibble, mllg/checkmate, tidyverse/dplyr, yihui/knitr, r-lib/lifecycle, rstudio/rmarkdown, gagolews/stringi, r-lib/testthat, r-lib/withr |
Config/Needs/website: | insightsengineering/nesttemplate |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
Language: | en-US |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-06-13 16:02:38 UTC; melkiades |
Author: | Gabriel Becker [aut] (original creator of the package),
Adrian Waddell [aut],
Joe Zhu |
Maintainer: | Joe Zhu <joe.zhu@roche.com> |
Repository: | CRAN |
Date/Publication: | 2025-06-15 14:30:02 UTC |
rlistings: Clinical Trial Style Data Readout Listings
Description
Listings are often part of the submission of clinical trial data in regulatory settings. We provide a framework for the specific formatting features often used when displaying large datasets in that context.
Author(s)
Maintainer: Joe Zhu joe.zhu@roche.com (ORCID)
Authors:
Gabriel Becker gabembecker@gmail.com (original creator of the package)
Adrian Waddell adrian.waddell@gene.com
Davide Garolini davide.garolini@roche.com (ORCID)
Emily de la Rua emily.de_la_rua@contractors.roche.com (ORCID)
Other contributors:
Abinaya Yogasekaram abinaya.yogasekaram@contractors.roche.com (ORCID) [contributor]
F. Hoffmann-La Roche AG [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/insightsengineering/rlistings/issues
Create a listing from a data.frame
or tibble
Description
Create listings displaying key_cols
and disp_cols
to produce a compact and
elegant representation of the input data.frame
or tibble
.
Usage
as_listing(
df,
key_cols = names(df)[1],
disp_cols = NULL,
non_disp_cols = NULL,
sort_cols = key_cols,
unique_rows = FALSE,
default_formatting = list(all = fmt_config()),
col_formatting = NULL,
align_colnames = FALSE,
add_trailing_sep = NULL,
trailing_sep = " ",
main_title = NULL,
subtitles = NULL,
main_footer = NULL,
prov_footer = NULL,
split_into_pages_by_var = NULL,
spanning_col_labels = no_spans_df
)
spanning_col_label_df(df)
spanning_col_label_df(df) <- value
as_keycol(vec)
is_keycol(vec)
get_keycols(df)
listing_dispcols(df)
add_listing_dispcol(df, new)
listing_dispcols(df) <- value
align_colnames(df)
align_colnames(df) <- value
add_listing_col(
df,
name,
fun = NULL,
format = NULL,
na_str = "NA",
align = "left"
)
Arguments
df |
( |
key_cols |
( |
disp_cols |
( |
non_disp_cols |
( |
sort_cols |
( |
unique_rows |
( |
default_formatting |
( |
col_formatting |
( |
align_colnames |
( |
add_trailing_sep |
( |
trailing_sep |
( |
main_title |
( |
subtitles |
( |
main_footer |
( |
prov_footer |
( |
split_into_pages_by_var |
( |
spanning_col_labels |
( |
value |
( |
vec |
( |
new |
( |
name |
( |
fun |
( |
format |
( |
na_str |
( |
align |
( |
Details
At its core, a listing_df
object is a tbl_df
object with a customized
print method and support for the formatting and pagination machinery provided by
the formatters
package.
listing_df
objects have two 'special' types of columns: key columns and display columns.
Key columns act as indexes, which means a number of things in practice.
All key columns are also display columns.
listing_df
objects are always sorted by their set of key columns at creation time.
Any listing_df
object which is not sorted by its full set of key columns (e.g.,
one whose rows have been reordered explicitly during creation) is invalid and the behavior
when rendering or paginating that object is undefined.
Each value of a key column is printed only once per page and per unique combination of values for all higher-priority (i.e., to the left of it) key columns. Locations where a repeated value would have been printed within a key column for the same higher-priority-key combination on the same page are rendered as empty space. Note, determination of which elements to display within a key column at rendering is based on the underlying value; any non-default formatting applied to the column has no effect on this behavior.
Display columns are columns which should be rendered, but are not key columns. By default this is all non-key columns in the incoming data, but in need not be. Columns in the underlying data which are neither key nor display columns remain within the object available for computations but are not rendered during printing or export of the listing.
Spanning column labels are displayed centered above the individual labels
of the columns they span across. span_level
1 is placed directly above
the column labels, with higher "span_levels' displayed above it in ascending
order.
IF spanning column labels are present, a single spanning label cannot span across both key and non-key displayed columns simultaneously due to key columns' repetition after page breaks during horizontal pagination. Attempting to set a spanning column label which does so will result in an error.
Value
A listing_df
object, sorted by its key columns.
df
with name
created (if necessary) and marked for
display during rendering.
Note
Unlike in the rtables
sister package, spanning labels here are purely
decorative and do not reflect any structure among the columns modeled by
rlistings
. Thus, we cannot, e.g., use pathing to select columns under
a certain spanning column label, or restrict horizontal pagination to
leave 'groups' of columns implied by a spanning label intact.
Examples
dat <- ex_adae
# This example demonstrates the listing with key_cols (values are grouped by USUBJID) and
# multiple lines in prov_footer
lsting <- as_listing(dat[1:25, ],
key_cols = c("USUBJID", "AESOC"),
main_title = "Example Title for Listing",
subtitles = "This is the subtitle for this Adverse Events Table",
main_footer = "Main footer for the listing",
prov_footer = c(
"You can even add a subfooter", "Second element is place on a new line",
"Third string"
)
) %>%
add_listing_col("AETOXGR") %>%
add_listing_col("BMRKR1", format = "xx.x") %>%
add_listing_col("AESER / AREL", fun = function(df) paste(df$AESER, df$AREL, sep = " / "))
mat <- matrix_form(lsting)
cat(toString(mat))
# This example demonstrates the listing table without key_cols
# and specifying the cols with disp_cols.
dat <- ex_adae
lsting <- as_listing(dat[1:25, ],
disp_cols = c("USUBJID", "AESOC", "RACE", "AETOXGR", "BMRKR1")
)
mat <- matrix_form(lsting)
cat(toString(mat))
# This example demonstrates a listing with format configurations specified
# via the default_formatting and col_formatting arguments
dat <- ex_adae
dat$AENDY[3:6] <- NA
lsting <- as_listing(dat[1:25, ],
key_cols = c("USUBJID", "AESOC"),
disp_cols = c("STUDYID", "SEX", "ASEQ", "RANDDT", "ASTDY", "AENDY"),
default_formatting = list(
all = fmt_config(align = "left"),
numeric = fmt_config(
format = "xx.xx",
na_str = "<No data>",
align = "right"
)
)
) %>%
add_listing_col("BMRKR1", format = "xx.x", align = "center")
mat <- matrix_form(lsting)
cat(toString(mat))
Utilities for formatting a listing column
Description
For vec_nlines
, calculate the number of lines each element of a column vector will
take to render. For format_colvector
,
Usage
format_colvector(df, colnm, colvec = df[[colnm]], round_type = c("iec", "sas"))
vec_nlines(
vec,
max_width = NULL,
fontspec = dflt_courier,
round_type = c("iec", "sas")
)
## S4 method for signature 'ANY'
vec_nlines(
vec,
max_width = NULL,
fontspec = dflt_courier,
round_type = c("iec", "sas")
)
Arguments
df |
( |
colnm |
( |
colvec |
( |
vec |
( |
max_width |
( |
Value
(numeric
)
a vector of the number of lines element-wise that will be
needed to render the elements of vec
to width max_width
.
Methods for listing_df
objects
Description
See core documentation in formatters::formatters-package for descriptions of these functions.
Usage
## S3 method for class 'listing_df'
print(
x,
widths = NULL,
tf_wrap = FALSE,
max_width = NULL,
fontspec = NULL,
col_gap = 3L,
round_type = c("iec", "sas"),
...
)
## S4 method for signature 'listing_df'
toString(
x,
widths = NULL,
fontspec = NULL,
col_gap = 3L,
round_type = c("iec", "sas"),
...
)
## S4 method for signature 'listing_df'
x[i, j, drop = FALSE]
## S4 method for signature 'listing_df'
main_title(obj)
## S4 method for signature 'listing_df'
subtitles(obj)
## S4 method for signature 'listing_df'
main_footer(obj)
## S4 method for signature 'listing_df'
prov_footer(obj)
## S4 replacement method for signature 'listing_df'
main_title(obj) <- value
## S4 replacement method for signature 'listing_df'
subtitles(obj) <- value
## S4 replacement method for signature 'listing_df'
main_footer(obj) <- value
## S4 replacement method for signature 'listing_df'
prov_footer(obj) <- value
## S4 method for signature 'listing_df'
num_rep_cols(obj)
Arguments
x |
( |
widths |
( |
tf_wrap |
( |
max_width |
( |
fontspec |
( |
col_gap |
( |
round_type |
( |
... |
additional parameters passed to |
i |
( |
j |
( |
drop |
relevant for matrices and arrays. If |
obj |
( |
value |
typically an array-like R object of a similar class as
|
Value
Accessor methods return the value of the aspect of
obj
.Setter methods return
obj
with the relevant element of the listing updated.
Examples
lsting <- as_listing(mtcars)
main_title(lsting) <- "Hi there"
main_title(lsting)
Make pagination data frame for a listing
Description
Make pagination data frame for a listing
Usage
## S4 method for signature 'listing_df'
make_row_df(
tt,
colwidths = NULL,
visible_only = TRUE,
rownum = 0,
indent = 0L,
path = character(),
incontent = FALSE,
repr_ext = 0L,
repr_inds = integer(),
sibpos = NA_integer_,
nsibs = NA_integer_,
fontspec = dflt_courier,
round_type = c("iec", "sas")
)
Arguments
tt |
( |
colwidths |
( |
visible_only |
( |
rownum |
( |
indent |
( |
path |
( |
incontent |
( |
repr_ext |
( |
repr_inds |
( |
sibpos |
( |
nsibs |
( |
fontspec |
( |
round_type |
( |
Value
a data.frame
with pagination information.
See Also
Examples
lsting <- as_listing(mtcars)
mf <- matrix_form(lsting)
Transform rtable
to a list of matrices which can be used for outputting
Description
Although rtable
s are represented as a tree data structure when outputting the table to ASCII or HTML,
it is useful to map the rtable
to an in-between state with the formatted cells in a matrix form.
Usage
## S4 method for signature 'listing_df'
matrix_form(
obj,
indent_rownames = FALSE,
expand_newlines = TRUE,
fontspec = font_spec,
col_gap = 3L,
round_type = c("iec", "sas")
)
Arguments
obj |
( |
indent_rownames |
( |
expand_newlines |
( |
fontspec |
( |
col_gap |
( |
round_type |
( |
Value
a formatters::MatrixPrintForm object.
See Also
Examples
lsting <- as_listing(mtcars)
mf <- matrix_form(lsting)
Paginate listings
Description
Pagination of a listing. This can be vertical for long listings with many
rows and/or horizontal if there are many columns. This function is a wrapper of
formatters::paginate_to_mpfs()
and it is mainly meant for exploration and testing.
Usage
paginate_listing(
lsting,
page_type = "letter",
font_family = "Courier",
font_size = 8,
lineheight = 1,
landscape = FALSE,
pg_width = NULL,
pg_height = NULL,
margins = c(top = 0.5, bottom = 0.5, left = 0.75, right = 0.75),
lpp = NA_integer_,
cpp = NA_integer_,
colwidths = NULL,
tf_wrap = !is.null(max_width),
rep_cols = NULL,
max_width = NULL,
col_gap = 3,
fontspec = font_spec(font_family, font_size, lineheight),
verbose = FALSE,
print_pages = TRUE
)
Arguments
lsting |
( |
page_type |
( |
font_family |
( |
font_size |
( |
lineheight |
( |
landscape |
( |
pg_width |
( |
pg_height |
( |
margins |
( |
lpp |
( |
cpp |
( |
colwidths |
( |
tf_wrap |
( |
rep_cols |
( |
max_width |
( |
col_gap |
( |
fontspec |
( |
verbose |
( |
print_pages |
( |
Value
A list of listing_df
objects where each list element corresponds to a separate page.
Examples
dat <- ex_adae
lsting <- as_listing(dat[1:25, ], disp_cols = c("USUBJID", "AESOC", "RACE", "AETOXGR", "BMRKR1"))
mat <- matrix_form(lsting)
cat(toString(mat))
paginate_listing(lsting, lpp = 10)
paginate_listing(lsting, cpp = 100, lpp = 40)
paginate_listing(lsting, cpp = 80, lpp = 40, verbose = TRUE)
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- formatters
Examples
dat <- ex_adae
lsting <- as_listing(dat[1:25, ], key_cols = c("USUBJID", "AESOC")) %>%
add_listing_col("AETOXGR") %>%
add_listing_col("BMRKR1", format = "xx.x") %>%
add_listing_col("AESER / AREL", fun = function(df) paste(df$AESER, df$AREL, sep = " / "))
main_title(lsting) <- "this is some title"
main_footer(lsting) <- "this is some footer"
cat(export_as_txt(lsting, file = NULL, paginate = TRUE))
Split Listing by Values of a Variable
Description
Split is performed based on unique values of the given parameter present in the listing. Each listing can only be split by variable once. If this function is applied prior to pagination, parameter values will be separated by page.
Usage
split_into_pages_by_var(lsting, var, page_prefix = var)
Arguments
lsting |
( |
var |
( |
page_prefix |
( |
Value
A list of lsting_df
objects each corresponding to a unique value of var
.
Note
This function should only be used after the complete listing has been created. The listing cannot be modified further after applying this function.
Examples
dat <- ex_adae[1:20, ]
lsting <- as_listing(
dat,
key_cols = c("USUBJID", "AGE"),
disp_cols = "SEX",
main_title = "title",
main_footer = "footer"
) %>%
add_listing_col("BMRKR1", format = "xx.x") %>%
split_into_pages_by_var("SEX")
lsting