| Title: | Tools for Analysing HIPEC Patient Data |
|---|---|
| Description: | Provides helper functions for analysing patient data in hyperthermic intraperitoneal chemotherapy (HIPEC) workflows. Includes functions to estimate peritoneal surface area (PSA), summarise registry data, and produce reporting graphics. Body surface area calculations are based on Du Bois and Du Bois (1916) <doi:10.1001/archinte.1916.00080130010002>. |
| Authors: | Tarkan Jaeger [aut, cre] |
| Maintainer: | Tarkan Jaeger <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.0.0 |
| Built: | 2026-05-22 08:25:00 UTC |
| Source: | https://github.com/tarjae/hipecr |
This function calculates the age of a person by given birthdate and the end date
tar_age(birth_date, x_date)tar_age(birth_date, x_date)
birth_date |
A date value, e.g. "1974-11-23". |
x_date |
A date value until the age lasts, e.g. "2023-02-16". |
A numeric value in (years)
tar_age("1974-11-23", "2023-02-16")tar_age("1974-11-23", "2023-02-16")
This function creates an animated bar chart with customizable colors and orientation. The resulting GIF can be saved to a specified filename.
tar_animbar( x, filename = "my_animated_bar", color1 = "steelblue1", color2 = "purple3", title = "%", horizontal = FALSE, total = 100, fps = 24, base_duration = 15, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )tar_animbar( x, filename = "my_animated_bar", color1 = "steelblue1", color2 = "purple3", title = "%", horizontal = FALSE, total = 100, fps = 24, base_duration = 15, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )
x |
An integer indicating the value for the bar chart. |
filename |
A string specifying the name of the output file (default: "my_animated_bar"). |
color1 |
A string specifying the color for the first part of the bar (default: "steelblue1"). |
color2 |
A string specifying the color for the second part of the bar (default: "purple3"). |
title |
A string specifying the title suffix for the animation (default: percent sign). |
horizontal |
A logical value indicating whether the bar chart should be horizontal (default: FALSE). |
total |
An integer indicating the maximum value for the bar chart scale (default: 100). |
fps |
Frames per second for the animation (default: 24). |
base_duration |
Base duration (seconds) for a full-scale animation (default: 15). |
output_dir |
Output directory for the GIF (default: temporary directory). |
overwrite |
Logical; overwrite an existing GIF (default: FALSE). |
ask |
Logical; if TRUE, prompt when file exists (default: interactive()). |
This function generates an animated bar chart with customizable colors and orientation. The resulting GIF can be saved to a specified filename.
Invisible path to the generated GIF file.
if (interactive() && requireNamespace("gifski", quietly = TRUE)) { tar_animbar(x = 10, filename = "a3", color1 = "gold", color2 = "purple3", horizontal = TRUE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) tar_animbar(x = 5, filename = "a4", color1 = "steelblue", color2 = "purple3", horizontal = FALSE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) tar_animbar(x = 3, filename = "rapido_LRR", horizontal = FALSE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) }if (interactive() && requireNamespace("gifski", quietly = TRUE)) { tar_animbar(x = 10, filename = "a3", color1 = "gold", color2 = "purple3", horizontal = TRUE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) tar_animbar(x = 5, filename = "a4", color1 = "steelblue", color2 = "purple3", horizontal = FALSE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) tar_animbar(x = 3, filename = "rapido_LRR", horizontal = FALSE, total = 10, fps = 5, base_duration = 1, output_dir = tempdir(), overwrite = TRUE, ask = FALSE) }
Calculating BMI (kg/m^2)
tar_bmi(weight, height)tar_bmi(weight, height)
weight |
Numeric, kg |
height |
Numeric, cm |
body mass index BMI
tar_bmi(weight = 100, height = 190)tar_bmi(weight = 100, height = 190)
This function calculates the body surface area with the DuBois method. DuBois D. A formula to estimate the approximate surface area if height and body mass are known. Arch Intern Med 1916;17:863-71.
tar_bsa(height, weight)tar_bsa(height, weight)
height |
A numeric value in cm |
weight |
A numeric value in kg |
A numeric value in m^2
tar_bsa(height = 180, weight = 80) # ~1.996421 m^2tar_bsa(height = 180, weight = 80) # ~1.996421 m^2
Coerce raw input into a one-row data frame with registry fields.
tar_cast_data(data)tar_cast_data(data)
data |
A list or data frame with registry fields. |
A one-row data frame with standard column types.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Counts NA values across columns.
tar_count_na(df)tar_count_na(df)
df |
A data frame or tibble. |
A named numeric vector with NA counts per column.
if(interactive()){ tar_count_na(mtcars) }if(interactive()){ tar_count_na(mtcars) }
This function transforms the specified factor variable within a dataframe to lump all but the top n most frequent levels into an 'Other' category and then computes the count of each level.
tar_count_top(df, var, n = 5)tar_count_top(df, var, n = 5)
df |
A data frame containing the variable to be manipulated. |
var |
The variable (unquoted) within the data frame. |
n |
The number of top levels to keep before lumping others into 'Other'; default is 5. |
This function leverages 'dplyr' for data manipulation and 'forcats' for managing factor levels. It is particularly useful in data summarization where the focus is on the most frequent categories.
A dataframe showing the count of each level including 'Other' for all lumped lesser categories.
if(interactive()){ data <- data.frame(color = c("red", "blue", "green", "blue", "blue", "red", "yellow", "red")) print(tar_count_top(data, color, n = 2)) }if(interactive()){ data <- data.frame(color = c("red", "blue", "green", "blue", "blue", "red", "yellow", "red")) print(tar_count_top(data, color, n = 2)) }
Add a new record to the in-memory 'responses' data frame.
tar_create_data(data)tar_create_data(data)
data |
A named list or data frame with registry fields. |
Invisible NULL.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Return an empty default registry record.
tar_create_default_record()tar_create_default_record()
A one-row data frame with default values.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Handles date format in Austrian HIPEC Registry(c)
tar_dateInput(inputId, label)tar_dateInput(inputId, label)
inputId |
character |
label |
character |
Wraps shinyWidgets::airDatepickerInput with fixed defaults.
A date input in dd-MM-yyyy format.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Delete a record from 'responses' by id.
tar_delete_data(data)tar_delete_data(data)
data |
A list or data frame containing an 'id' field. |
Invisible NULL.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
This function takes a data frame 'df' and a vector of key values 'mykeyvalues'. It returns an unnamed vector of corresponding results by performing lookups in the data frame.
tar_dgav_lookup(df, mykeyvalues)tar_dgav_lookup(df, mykeyvalues)
df |
data frame with Name and azl number |
mykeyvalues |
is a vector containing the key values to be looked up in the data frame. These key values can be either numeric or character strings. The function processes each key value individually to determine if it matches entries in the specified columns of the data frame |
a key or value, depending on what is wanted
# Example data df <- data.frame( Name = c("Hans", "Maria", "Franz HUBER"), azl = c("1006341612", "1040405318", "1060707219"), stringsAsFactors = FALSE ) tar_dgav_lookup(df, "HUBER") # Should return "1060707219" tar_dgav_lookup(df, "huber") # Should also return "1060707219" tar_dgav_lookup(df, "Franz") # Should return "1060707219" tar_dgav_lookup(df, 1006341612) # Should return "Hans" tar_dgav_lookup(df, c(1006341612, 1040405318)) # Should return "Hans" "Maria" # Function to handle inputs for data frame# Example data df <- data.frame( Name = c("Hans", "Maria", "Franz HUBER"), azl = c("1006341612", "1040405318", "1060707219"), stringsAsFactors = FALSE ) tar_dgav_lookup(df, "HUBER") # Should return "1060707219" tar_dgav_lookup(df, "huber") # Should also return "1060707219" tar_dgav_lookup(df, "Franz") # Should return "1060707219" tar_dgav_lookup(df, 1006341612) # Should return "Hans" tar_dgav_lookup(df, c(1006341612, 1040405318)) # Should return "Hans" "Maria" # Function to handle inputs for data frame
This function downloads flag images of specified countries, combines them vertically with spaces in between, and saves the combined image to a file.
tar_flag( countries, name, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )tar_flag( countries, name, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )
countries |
A character vector of country codes (ISO 3166\-1 alpha\-2). |
name |
A character string for the name of the study. This will be used to construct the output file name. |
output_dir |
A directory for the output file (default: temporary directory). |
overwrite |
Logical; overwrite an existing PNG (default: FALSE). |
ask |
Logical; if TRUE, prompt when file exists (default: interactive()). |
Invisible path to the saved PNG file.
if (interactive()) { tar_flag(c("nl", "se", "es", "si", "dk", "no", "us"), "rapido") tar_flag(c("at", "de"), "demo", output_dir = tempdir(), overwrite = TRUE) }if (interactive()) { tar_flag(c("nl", "se", "es", "si", "dk", "no", "us"), "rapido") tar_flag(c("at", "de"), "demo", output_dir = tempdir(), overwrite = TRUE) }
This function takes a 'grViz' graph object, adds a footnote with specified style and text, and saves the graph along with the footnote as a PNG file. The PNG file is named based on the graph object name.
tar_footnote( graph, style, string, filename = NULL, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )tar_footnote( graph, style, string, filename = NULL, output_dir = tempdir(), overwrite = FALSE, ask = interactive() )
graph |
A 'grViz' graph object. |
style |
A character string specifying the CSS style for the footnote. |
string |
A character string specifying the footnote text. |
filename |
Optional output filename (without extension). Defaults to the variable name of 'graph' if possible. |
output_dir |
Output directory (default: temporary directory). |
overwrite |
Logical; overwrite an existing PNG (default: FALSE). |
ask |
Logical; if TRUE, prompt when file exists (default: interactive()). |
None. The function saves a PNG file in the working directory.
if (interactive() && requireNamespace("DiagrammeR", quietly = TRUE)) { graph <- DiagrammeR::grViz(" digraph { graph [layout = dot] node [shape = box] a [label = 'A'] b [label = 'B'] a -> {b} } ") style <- "color: grey; font-family: Arial; text-align: left; font-size: 10px;" string <- paste( "CNCT = Consolidation Chemotherapy,", "CRT = Chemoradiotherapy,", "CT = Chemotherapy,", "INCT = Induction Chemotherapy,", "SCRT = Short-course Radiotherapy,", "TME = Total Mesorectal Excision,", "WW = Watch and Wait,", sep = " " ) tar_footnote(graph, style, string) }if (interactive() && requireNamespace("DiagrammeR", quietly = TRUE)) { graph <- DiagrammeR::grViz(" digraph { graph [layout = dot] node [shape = box] a [label = 'A'] b [label = 'B'] a -> {b} } ") style <- "color: grey; font-family: Arial; text-align: left; font-size: 10px;" string <- paste( "CNCT = Consolidation Chemotherapy,", "CRT = Chemoradiotherapy,", "CT = Chemotherapy,", "INCT = Induction Chemotherapy,", "SCRT = Short-course Radiotherapy,", "TME = Total Mesorectal Excision,", "WW = Watch and Wait,", sep = " " ) tar_footnote(graph, style, string) }
Get the next numeric ID based on the 'responses' data frame.
tar_get_next_id()tar_get_next_id()
Integer ID.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Create a named vector of fields and labels for the registry.
tar_get_table_metadata(variable = fieldsAll, label = label_names)tar_get_table_metadata(variable = fieldsAll, label = label_names)
variable |
Character vector of field names. Default: fieldsAll. |
label |
Character vector of labels. Default: label_names. |
Expects 'variable' and 'label' to be the same length.
A list with element 'fields', a named character vector.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
This function adjusts the sizes of various theme elements in a ggplot2 plot. It takes a single argument which is the base size for geom_text, and it calculates the theme sizes based on this.
tar_ggplot_font_size(geom_text_size = 7)tar_ggplot_font_size(geom_text_size = 7)
geom_text_size |
The base size for text elements in 'geom_text'. Default is 7. |
Always add the same size as in geom_text, then all fonts will have the same size. Default size is 7. If there is no geom_text we can control the font size of axis, legend, title and text with this function.
A 'theme' object that can be added to a ggplot.
The formula is from here: https://stackoverflow.com/questions/25061822/ggplot-geom-text-font-size-control
library(ggplot2) p <- ggplot(mtcars, aes(factor(vs), y = mpg, fill = factor(am))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "my_title") + tar_ggplot_font_size(10) print(p)library(ggplot2) p <- ggplot(mtcars, aes(factor(vs), y = mpg, fill = factor(am))) + geom_bar(stat = "identity", position = "dodge") + labs(title = "my_title") + tar_ggplot_font_size(10) print(p)
This function returns the first 'nh' = n head and last 'nt' = n tail rows of a dataframe or tibble. Row numbers from the original data are preserved as row names in the result.
tar_head_tail(data, nh = 5, nt = 5)tar_head_tail(data, nh = 5, nt = 5)
data |
A data frame or tibble whose head and tail you wish to view. |
nh |
An integer specifying the number of rows from the start of 'data' to display. Default is 5. |
nt |
An integer specifying the number of rows from the end of 'data' to display. Default is 5. |
A dataframe composed of the first 'nh' and last 'nt' rows of the input data. The row numbers from the original data are used as row names in the result.
if(interactive()){ # Generate example data df <- data.frame(A = 1:10, B = 11:20) tar_head_tail(df, nh = 3, nt = 2) }if(interactive()){ # Generate example data df <- data.frame(A = 1:10, B = 11:20) tar_head_tail(df, nh = 3, nt = 2) }
Imputates outliers and shows 4 different method plots
tar_impute_outlier(df, variable)tar_impute_outlier(df, variable)
df |
data frame or tibble where the numeric variable lives |
variable |
Numeric variable column in the data frame |
4 plots with mean, median, mode and capping imputation
if (interactive()) { tar_impute_outlier(mtcars, mpg) }if (interactive()) { tar_impute_outlier(mtcars, mpg) }
Helper that returns an 'install.packages()' command for a package name.
tar_install(x)tar_install(x)
x |
The name of the package you want to install. |
This function uses non-standard evaluation to allow you to specify the package name unquoted.
A character string with the corresponding 'install.packages()' command.
tar_install(dplyr)tar_install(dplyr)
This function fits a survival model, plots the survival curves, and annotates median survival times. The plot can optionally be saved to file.
tar_median_survival( df, var, time_col = "time", status_col = "status", output_file = NULL )tar_median_survival( df, var, time_col = "time", status_col = "status", output_file = NULL )
df |
A data frame containing the survival data. |
var |
A variable used for grouping the survival curves. |
time_col |
A string specifying the name of the column representing time. |
status_col |
A string specifying the name of the column representing status. |
output_file |
Optional output path for saving the plot. If 'NULL' (default), the function does not write a file. |
A 'ggsurvplot' object (invisibly). Optionally writes a PNG file.
# Example dataset df_survival <- structure( list( status = c(1, 0, 1, 1, 1, 1, 0, 1, 1, 0), primorgan = structure( c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L), levels = c("Colon", "Rectum"), class = "factor" ), sex = structure( c("male", "female", "male", "male", "male", "male", "male", "male", "male", "female"), label = "Gender" ), time = c(4.26, 49.52, 18.05, 11.04, 47.67, 8.03, 76.2, 15.44, 22.74, 50.64), subtype = structure( c(2L, 1L, 2L, 3L, 2L, 3L, 1L, 1L, 1L, 2L), levels = c("adenocarcinoma", "mucinous", "signet ring cell"), label = "Histological subtype", class = "factor" ) ), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame") ) tar_median_survival( df = df_survival, var = sex, time_col = "time", status_col = "status", output_file = file.path(tempdir(), "survival_sex.png") )# Example dataset df_survival <- structure( list( status = c(1, 0, 1, 1, 1, 1, 0, 1, 1, 0), primorgan = structure( c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L), levels = c("Colon", "Rectum"), class = "factor" ), sex = structure( c("male", "female", "male", "male", "male", "male", "male", "male", "male", "female"), label = "Gender" ), time = c(4.26, 49.52, 18.05, 11.04, 47.67, 8.03, 76.2, 15.44, 22.74, 50.64), subtype = structure( c(2L, 1L, 2L, 3L, 2L, 3L, 1L, 1L, 1L, 2L), levels = c("adenocarcinoma", "mucinous", "signet ring cell"), label = "Histological subtype", class = "factor" ) ), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame") ) tar_median_survival( df = df_survival, var = sex, time_col = "time", status_col = "status", output_file = file.path(tempdir(), "survival_sex.png") )
Creates a one-liner from a multiline code example in the clipboard.
tar_oneline()tar_oneline()
A character vector with the reformatted one-line code.
if (interactive()) { # Your multiline string # copy this code numericInput( "Register_Nr", "Nr.", min = 0, max = 20, step = 1, value = 0 ) # then apply tar_oneline() }if (interactive()) { # Your multiline string # copy this code numericInput( "Register_Nr", "Nr.", min = 0, max = 20, step = 1, value = 0 ) # then apply tar_oneline() }
This function sets the 'pillar.print_min' option in R. This option controls globally the minimum number of data to print in tibbles. In contrast to data frames, in tibbles only 10 lines are shown except you use print(n=...). But you have to add it each time. tar_print can be use once globally and changed whenever necessayr!
tar_print(value = 50)tar_print(value = 50)
value |
A single non-negative integer for the minimum number of rows shown of a tibble in the console. Defaults to 50. |
Invisible null. The function is called for its side effect of setting an option.
The formula is from here: https://stackoverflow.com/questions/77708674/is-there-a-global-option-to-adjust-the-default-setting-of-tibbles-that-displays
tar_print(100) # Set the pillar.print_min option to 100 tar_print() # Set the pillar.print_min option back to default (50)tar_print(100) # Set the pillar.print_min option to 100 tar_print() # Set the pillar.print_min option back to default (50)
This function calculates 1 the given height and weight. It's used as a factor for further calculations.
tar_psa(height, weight)tar_psa(height, weight)
height |
A numeric value representing the height in cm. |
weight |
A numeric value representing the weight in kg. |
A numeric value representing 1
tar_psa(180, 80) # Expected output: 199.6421 cm^2tar_psa(180, 80) # Expected output: 199.6421 cm^2
Return the in-memory 'responses' data frame, if present.
tar_read_data()tar_read_data()
A data frame or NULL if not available.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Update an existing record in 'responses' by row name.
tar_update_data(data)tar_update_data(data)
data |
A named list or data frame with registry fields. |
Invisible NULL.
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Push a registry record into Shiny input controls.
tar_update_inputs(data, session)tar_update_inputs(data, session)
data |
A one-row data frame with registry fields. |
session |
Shiny session. |
Invisible NULL.
updateTextInput, updateNumericInput, updateDateInput
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Creates a shinydashboard box equivalent with shiny
tar_WellPanel(n)tar_WellPanel(n)
n |
integer the gives the number of months in follow-up |
Builds a wellPanel containing follow-up inputs for the given month.
returns a wellpanel a quasi shinydashboard box (without ShinyDashboard)
if(interactive()){ #EXAMPLE1 }if(interactive()){ #EXAMPLE1 }
Converts a Windows path (for example, C:/Users/... or
C:\Users\...) into a WSL path (/mnt/c/Users/... by default).
Optionally copies the converted path to the clipboard.
tar_wsl_pfad(path = getwd(), copy_to_clipboard = TRUE, mount_root = "/mnt")tar_wsl_pfad(path = getwd(), copy_to_clipboard = TRUE, mount_root = "/mnt")
path |
A single Windows path string. Defaults to |
copy_to_clipboard |
Logical. If |
mount_root |
Mount root used by WSL. Defaults to |
A single character string with the converted WSL path.
tar_wsl_pfad("C:/Users/tarka/project", copy_to_clipboard = FALSE) tar_wsl_pfad("C:\\Users\\tarka\\project", copy_to_clipboard = FALSE)tar_wsl_pfad("C:/Users/tarka/project", copy_to_clipboard = FALSE) tar_wsl_pfad("C:\\Users\\tarka\\project", copy_to_clipboard = FALSE)
This function takes a vector and converts all instances of "yes" to 1, "no" to 0, and leaves other values as NA. It's useful for converting categorical "yes"/"no" responses into a numeric format that can be used in statistical analysis.
tar_yes_no(x)tar_yes_no(x)
x |
A vector containing elements to be converted. Elements should be character strings potentially including "yes" and "no". |
A numeric vector where "yes" is replaced with 1, "no" with 0, and other values with NA.
test_vector <- c("yes", "no", "maybe", "yes", "no") tar_yes_no(test_vector)test_vector <- c("yes", "no", "maybe", "yes", "no") tar_yes_no(test_vector)