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] |
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 |
Convert a flextable into a clintable object
as_clintable(x, page_by = NULL, group_by = NULL)
as_clintable(x, page_by = NULL, group_by = NULL)
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 |
A clintable object
ft <- flextable::flextable(mtcars) as_clintable(ft)
ft <- flextable::flextable(mtcars) as_clintable(ft)
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.
clin_add_titles(x, ls = NULL, ft = NULL) clin_add_footnotes(x, ls = NULL, ft = NULL)
clin_add_titles(x, ls = NULL, ft = NULL) clin_add_footnotes(x, ls = NULL, ft = NULL)
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 |
A clintable object
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") ) ) )
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") ) ) )
This function configures alternating pages on a clintable object.
clin_alt_pages(x, key_cols, col_groups)
clin_alt_pages(x, key_cols, col_groups)
x |
A clintable object |
key_cols |
A character vector of variable names |
col_groups |
A list of character vectors of variable names |
A clintable object
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') ) )
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') ) )
Extraction of flextable print method with special handling of clintable pages and
clin_col_widths(x, ...)
clin_col_widths(x, ...)
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 |
A clintable object
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)
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)
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.
clin_column_headers(x, ...)
clin_column_headers(x, ...)
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. |
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.
A clintable object
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") )
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") )
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.
clin_default_table_width()
clin_default_table_width()
An rdocx object from the officer package
Configure a clintable to table by a grouping variable, which will be used as a label
clin_group_by(x, group_by)
clin_group_by(x, group_by)
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 |
A clintable object
clintable(iris) |> clin_group_by('Species')
clintable(iris) |> clin_group_by('Species')
Configure pagination using a page variable
clin_page_by(x, page_by, max_rows = 10)
clin_page_by(x, page_by, max_rows = 10)
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 |
A clintable object
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)
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)
Default document attributes assume landscape A4 paper size
clinify_docx_default()
clinify_docx_default()
An rdocx object from the officer package
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
clinify_footnotes_default(x, ...)
clinify_footnotes_default(x, ...)
x |
flextable object that is modified by the function. |
... |
any additional arguments |
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
None
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.
clinify_table_default(x, ...)
clinify_table_default(x, ...)
x |
flextable object that is modified by the function. |
... |
any additional arguments |
None
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
clinify_titles_default(x, ...)
clinify_titles_default(x, ...)
x |
flextable object that is modified by the function. |
... |
any additional arguments |
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
None
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
clintable(x, page_by = NULL, group_by = NULL, use_labels = TRUE, ...)
clintable(x, page_by = NULL, group_by = NULL, use_labels = TRUE, ...)
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 |
A clintable object
clintable(mtcars)
clintable(mtcars)
Create a new title or footnote flextable
new_title_footnote(x, sect = c("titles", "footnotes"))
new_title_footnote(x, sect = c("titles", "footnotes"))
x |
a list of character vectors, no more than 3 elements to a vector. |
sect |
Either "titles" or "footnotes" |
A flextable object
#TODO:
#TODO:
Extraction of flextable print method with special handling of clintable pages and
## S3 method for class 'clintable' print(x, n = 3, nrows = 15, apply_defaults = TRUE, ...) ## S3 method for class 'clintable' knit_print(x, n = 3, nrows = 15, apply_defaults = TRUE, ...)
## S3 method for class 'clintable' print(x, n = 3, nrows = 15, apply_defaults = TRUE, ...) ## S3 method for class 'clintable' knit_print(x, n = 3, nrows = 15, apply_defaults = TRUE, ...)
x |
A clintable object |
n |
Number of pages within the clintable to print. Only used when pagination is configured |
nrows |
Number of rows to print. Only used when rows aren't configured within the pagination method |
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. |
... |
Additional parameters passed to flextable print method |
Invisible
ct <- clintable(mtcars) print(ct) 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') ) ) print(ct)
ct <- clintable(mtcars) print(ct) 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') ) ) print(ct)
Write a clinify table out to a docx file
write_clintable(x, file, apply_defaults = TRUE)
write_clintable(x, file, apply_defaults = TRUE)
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. |
Invisible
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'))
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'))