Package 'clinify'

Title: Clinical Table Styling Tools and Utilities
Description: The primary motivation of this package is to take the things that are great about the R packages 'flextable' <https://davidgohel.github.io/flextable/> and 'officer' <https://davidgohel.github.io/officer/>, take the standard and complex pieces of formatting clinical tables for regulatory use, and simplify the tedious pieces.
Authors: Mike Stackhouse [aut, cre] , Ross Didenko [aut], Yevhenii Boiko [aut], Marat Zakirov [ctb], Roman Rogoza [ctb], Atorus Research, Inc. [cph], Incyte Corporation [cph]
Maintainer: Mike Stackhouse <[email protected]>
License: Apache License (>= 2)
Version: 0.1.2
Built: 2025-03-14 05:32:49 UTC
Source: https://github.com/atorus-research/clinify

Help Index


Convert a flextable into a clintable object

Description

Convert a flextable into a clintable object

Usage

as_clintable(x, page_by = NULL, group_by = NULL)

Arguments

x

A flextable object

page_by

A variable in the input dataframe to use for pagination

group_by

A variable which will be used for grouping and attached as a label above the table headers

Value

A clintable object

Examples

ft <- flextable::flextable(mtcars)
as_clintable(ft)

Add page footer

Description

This function adds a text, passed as argument, into .docx bottom colontitle (page footer). As a result, the text is repeated on each page of the document. Takes a list of lists as an input parameter, where each sublist represents a separate line (or row) of text. There is also a possibility to add a row with both left- and right-aligned text. To do so - simply pass two items to a sublist instead of one.

Usage

clin_add_titles(x, ls = NULL, ft = NULL)

clin_add_footnotes(x, ls = NULL, ft = NULL)

Arguments

x

a clintable object

ls

a list of character vectors, no more than 3 elements to a vector

ft

A flextable object to use as the header

Value

A clintable object

Examples

clintable(mtcars) |> 
  clin_add_titles(
    list(
      c("Left", "Center", "Right"),
      c("Just the middle")
    )
  ) |> 
  clin_add_footnotes(
    list(
      c(
        "Here's a footnote.", 
        format(Sys.time(), "%H:%M %A, %B %d, %Y")
      )
    )
  )

Configure alternating pages during pagination of a clintable

Description

This function configures alternating pages on a clintable object.

Usage

clin_alt_pages(x, key_cols, col_groups)

Arguments

x

A clintable object

key_cols

A character vector of variable names

col_groups

A list of character vectors of variable names

Value

A clintable object

Examples

ct <- clintable(mtcars)

clin_alt_pages(
  ct,
  key_cols = c('mpg', 'cyl', 'hp'),
  col_groups = list(
    c('disp', 'drat', 'wt'),
    c('qsec', 'vs', 'am'),
    c('gear', 'carb')
  )
)

Set column widths using percent

Description

Extraction of flextable print method with special handling of clintable pages and

Usage

clin_col_widths(x, ...)

Arguments

x

A clintable object

...

Named parameters where the names are columns in the flextable and the values are decimals representing the percent of total width of the table

Value

A clintable object

Examples

ct <- clintable(mtcars)

ct <- clin_alt_pages(
  ct,
  key_cols = c('mpg', 'cyl', 'hp'),
  col_groups = list(
    c('disp', 'drat', 'wt'),
    c('qsec', 'vs', 'am'),
    c('gear', 'carb')
  )
) |> 
clin_col_widths(mpg = .2, cyl=.2, disp=.15, vs=.15)

print(ct)

Set the column headers of the output clintable

Description

This function allows you to apply column headers named arguments and character vectors. Separate elements of the character vector are converted to separate levels of the output table header. The in which the headers are applied goes from top to bottom, so if you provide 3 elements for a column header, the first element is applied to the top and the second to the bottom. If one variable has three levels and other variable only have one or two, the columns with less levels to the header will bind to the bottom. So a column with two levels will apply to the second and third row, and a column with one level with apply the bottom row. Spanners are determined using cells of the same text value, where horizontal and vertical merging is performed.

Usage

clin_column_headers(x, ...)

Arguments

x

A clintable object

...

Named arguments providing the column header text. Separate levels of the header are determined using separate elements of a character vector.

Details

The same result can be achieved using column labels on the input dataframe to the clintable. If labels are present, header levels will be separated using the delimitter "||" within the label string.

Value

A clintable object

Examples

clintable(iris) |>
  clin_column_headers(
    Sepal.Length = c("Flowers", "Sepal", "Length"),  
    Sepal.Width = c("Flowers", "Sepal", "Width"),  
    Petal.Length = c("Petal", "Length"),  
    Petal.Width = c("Petal", "Width")
 )

Helper function to get the total page width

Description

Using the document dimensions stored in options, calculate the width that can be used in table body, titles, and footnotes. Calculation uses the page width subtracting right and left margins.

Usage

clin_default_table_width()

Value

An rdocx object from the officer package


Configure a clintable to table by a grouping variable, which will be used as a label

Description

Configure a clintable to table by a grouping variable, which will be used as a label

Usage

clin_group_by(x, group_by)

Arguments

x

A clintable object

group_by

A character vector of variable names which will be used for grouping and attached as a label above the table headers

Value

A clintable object

Examples

clintable(iris) |>
  clin_group_by('Species')

Configure pagination using a page variable

Description

Configure pagination using a page variable

Usage

clin_page_by(x, page_by, max_rows = 10)

Arguments

x

A clintable object

page_by

A variable in the input dataframe to use for pagination

max_rows

If no page_by, the maximum rows allowed per page

Value

A clintable object

Examples

dat <- mtcars
dat['page'] <- c(
  rep(1, 10),
  rep(2, 10),
  rep(3, 10),
  c(4, 4)
)

clintable(dat) |> 
  clin_page_by('page')

clintable(mtcars) |> 
  clin_page_by(max_rows=10)

Function to create a default officer docx object

Description

Default document attributes assume landscape A4 paper size

Usage

clinify_docx_default()

Value

An rdocx object from the officer package


The function to apply default footnote styling

Description

Next styling is applied: – font colour - black
– page footer should have single black top border over the top row that is width of 1
– all borders are removed
– font style - Courier New, 9pt, not bold, not italic
– interval between rows - 1 space
– padding - bottom = 0, top = 0

Usage

clinify_footnotes_default(x, ...)

Arguments

x

flextable object that is modified by the function.

...

any additional arguments

Details

One has to specify the width of the page header "table", which in this case is landscape page width (11.42 in) minus two times 1 in margin. ALL headers would have 3 columns underneath the hood (for left, center and right-aligned text). Hence we divide by 3 to specify the width of a single column

Value

None


The function to apply default table styling

Description

Headers with the same value are merged both horizontally and vertically All borders are clear except for the header (bleck, solid, 0.2pt) As well as top horizontal line for the table header. font style - Courier New, 9pt, not bold, not italic padding for table body - bottom = 0.1, top = 0.1 padding for table first header - top = 9 padding for table last header - bottom = 9 table's layout is set to be fixed.

Usage

clinify_table_default(x, ...)

Arguments

x

flextable object that is modified by the function.

...

any additional arguments

Value

None


The function to apply default title styling

Description

Next styling is applied: – font colour - black
– all borders are removed
– font style - Courier New, 9pt, not bold, not italic
– interval between rows - 1 space
– padding - bottom = 0, top = 0

Usage

clinify_titles_default(x, ...)

Arguments

x

flextable object that is modified by the function.

...

any additional arguments

Details

One has to specify the width of the page header "table", which in this case is landscape page width (11.42 in) minus two times 1 in margin. ALL headers would have 3 columns underneath the hood (for left, center and right-aligned text). Hence we divide by 3 to specify the width of a single column

Value

None


Create a new clintable object

Description

A clintable object directly inherits from a flextable object. This function will pass all necessary parameters flextable::flextable() and conver the object to a clintable

Usage

clintable(x, page_by = NULL, group_by = NULL, use_labels = TRUE, ...)

Arguments

x

A data frame

page_by

A variable in the input dataframe to use for pagination

group_by

A character vector of variable names which will be used for grouping and attached as a label above the table headers

use_labels

Use variable labels as column headers. Nested levels can be achieved using the string "||" as a delimitter. Horizontal and vertical levels using identical words will be merged.

...

Parameters to pass to flextable::flextable()

Value

A clintable object

Examples

clintable(mtcars)

Create a new title or footnote flextable

Description

Create a new title or footnote flextable

Usage

new_title_footnote(x, sect = c("titles", "footnotes"))

Arguments

x

a list of character vectors, no more than 3 elements to a vector.

sect

Either "titles" or "footnotes"

Value

A flextable object

Examples

#TODO:

Clintable write method

Description

Write a clinify table out to a docx file

Usage

write_clintable(x, file, apply_defaults = TRUE)

Arguments

x

a clintable object

file

The file path to which the file should be written

apply_defaults

Apply default styles. These styles are stored in the options clinify_header_default, clinify_footer_default, and clinify_table_default respectively. Defaults to true.

Value

Invisible

Examples

ct <- clintable(mtcars)

ct <- clin_alt_pages(
  ct,
  key_cols = c('mpg', 'cyl', 'hp'),
  col_groups = list(
    c('disp', 'drat', 'wt'),
    c('qsec', 'vs', 'am'),
    c('gear', 'carb')
  )
)

write_clintable(ct, file.path(tempdir(), 'demo.docx'))