save_table_to_Word: Save a bespoke PK table to Word using the pk_table rmarkdown...

View source: R/save_table_to_Word.R

save_table_to_WordR Documentation

Save a bespoke PK table to Word using the pk_table rmarkdown template

Description

save_table_to_Word will save a DIY PK table to Word using the same template file as is used for the function pk_table. UNDER CONSTRUCTION. I haven't done almost any error catching here yet. -LSh

Usage

save_table_to_Word(
  PKtable,
  save_table,
  existing_exp_details = NA,
  mean_type = "geometric",
  single_table = FALSE,
  include_dose_num = NA,
  prettify_columns = TRUE,
  fontsize = 11,
  merge_columns = NA,
  bold_cells = list(c(0, NA), c(NA, 1)),
  center_1st_column = FALSE,
  merge_shaded_cells = TRUE,
  highlight_so_cutoffs = NA,
  highlight_so_colors = NA,
  highlight_gmr_colors = NA
)

Arguments

PKtable

PK table (really, a data.frame or tibble) that includes the columns File, Statistic, Tissue, CompoundID, and then also columns named in the standard way (prettified or un-prettified) for PK parameters from the SimcypConsultancy package. Well, that is, your input for PKtable must meet those criteria if you want it to be formatted in any way or if you want to split it into multiple tables using the argument single_table or have highlighting applied with highlight_so_cutoffs. If you don't care about that, supply any old data.frame or tibble, and this will save it to Word. If you supply a flextable (see the eponymous package if you don't know what we're talking about), we also won't touch the formatting and will return your flextable as is in the Word document.

save_table

save the output table by supplying a file name in quotes here, e.g., "My nicely formatted table.docx". Do not include any slashes, dollar signs, or periods in the file name.

existing_exp_details

If you have already run extractExpDetails_mult to get all the details from the "Input Sheet" (e.g., when you ran extractExpDetails you said exp_details = "Input Sheet" or exp_details = "all"), we can use this information to make nicely annotated table headings and captions. Not strictly required, though.

mean_type

What kind of means and CVs do you want listed in the output table? Options are "arithmetic" or "geometric" (default).

single_table

TRUE (default) or FALSE for whether to save all the PK data in a single table or break the data up by tissue, compound ID, and file into multiple tables. This only applies to the Word output. If you want to save the file with multiple tables, we do need your PK table to be structures in a specific way so that we know where to separate things and how to format the resulting individual tables. Your entry for PKtable must contain the columns "File", "CompoundID", and "Tissue" for this to work well and must contain the column "File" to work at all.

include_dose_num

NA (default), TRUE, or FALSE on whether to include the dose number when listing the PK parameter. By default, the parameter will be labeled, e.g., "Dose 1 Cmax ratio" or "Last dose AUCtau ratio", if you have PK data for both the first dose and the last dose. Also by default, if you have data only for the first dose or only for the last dose, the dose number will be omitted and it will be labeled, e.g., "AUCtau ratio" or "Cmax ratio". Set this to TRUE or FALSE as desired to override the default behavior and get exactly what you want.

prettify_columns

TRUE (default) or FALSE for whether to make easily human-readable column names for any columns with PK parameters. TRUE makes pretty column names such as "Dose 1 AUCinf (h*ng/mL)" whereas FALSE leaves the column with the R-friendly name from extractPK, e.g., "AUCinf_dose1".

fontsize

the numeric font size for Word output. Default is 11 point. This only applies when you save the table as a Word file.

highlight_so_cutoffs

optionally specify cutoffs for highlighting any simulated-to-observed ratios. Anything that is above those values or below the inverse of those values will be highlighted. To figure out what cells to highlight, this looks for a column titled "Statistic" or "Stat", then looks for what row contains "S/O" or "simulated (something something) observed" (as in, we'll use some wildcards to try to match your specific text). Next, it looks for any values in that same row that are above those cutoffs. This overrides anything else you specified for highlighting. The default is NA, for not highlighting based on S/O value. Acceptable input for, say, highlighting values that are > 125% or < 80% of the observed and also, with a second color, values that are > 150% or < 66% would be: highlight_so_cutoffs = c(1.25, 1.5). If you would like the middle range of values to be highlighted, include 1 in your cutoffs. For example, say you would like everything that's < 80% or > 125% to be highlighted red but you'd like the "good" values from 80% to 125% to be green, you can get that by specifying highlight_so_cutoffs = c(1, 1.25) and highlight_so_colors = c("green", "red"). This only applies when you save the table as a Word file.

highlight_so_colors

optionally specify a set of colors to use in the Word file output for highlighting S/O values outside the limits you specified with highlight_so_cutoffs. Options:

"yellow to red" (default)

A range of light yellow to light orange to light red. If you have included 1 in your cutoffs and you leave highlight_so_colors with the default setting, values in the middle, "good" range of S/O values will be highlighted a light green.

"traffic"

light green, yellow, and red designed to display values outside 1.25, 1.5, and 2 fold of unity, respectively. If you include 1 in highlight_so_cutoffs, you'll get a darker green for "good" S/O values. This color scheme was borrowed from Lisa, so if you've seen her slides, these will look familiar.

a character vector of specific colors

Any R-acceptable colors, will work here, e.g., highlight_so_colors = c("yellow", "orange", "red")

If you do specify your own bespoke colors, you'll need to make sure that you supply one color for every value in highlight_so_cutoffs.

Value

saves a table to a Word file

Examples

MyPKTable <- tibble(Statistic = c("Simulated", "CV%", "Observed", "S/O"),
                        AUCinf = c(2756, 32.5, 1801, 1.53), 
                        Cmax = c(852, 45.8, 775, 1.1), 
                        `Half life` = c(7.75, 5.7, 6.05, 1.28))

## Not run: 
save_table_to_Word(MyPKTable, save_table = "My PK table.docx")

## End(Not run)


shirewoman2/Consultancy documentation built on Feb. 18, 2025, 10 p.m.