Title: | Enhance the Ease of R Experience as an Emerging Researcher |
---|---|
Description: | A toolkit of functions to help: i) effortlessly transform collected data into a publication ready format, ii) generate insightful visualizations from clinical data, iii) report summary statistics in a publication-ready format, iv) efficiently export, save and reload R objects within the framework of R projects. |
Authors: | Dahham Alsoud [cre, aut, cph] |
Maintainer: | Dahham Alsoud <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-03-06 04:18:18 UTC |
Source: | https://github.com/dahhamalsoud/phdcocktail |
Get a safe name to export a file without overwriting
get_safe_file_name( data, name = NULL, format = "xlsx", overwrite = FALSE, time_in_name = FALSE )
get_safe_file_name( data, name = NULL, format = "xlsx", overwrite = FALSE, time_in_name = FALSE )
data |
The object to be exported. |
name |
A desired name for the exported file. If no name is provided, the file will inherit the object's name. |
format |
The format of the exported file. Default is 'xlsx'. |
overwrite |
A logical to indicate whether preexisting files with identical names should be overwritten. Default is 'FALSE'. |
time_in_name |
A logical to indicate whether a timestamp should be included in the file's name. |
A safe name for exporting the file, as a "character string", and also indicated in a message.
if (FALSE) { library(phdcocktail) get_safe_file_name(mtcars) }
if (FALSE) { library(phdcocktail) get_safe_file_name(mtcars) }
Get a safe name to save current workspace without overwriting
get_safe_workspace_name(name = "analysis", time_in_name = TRUE)
get_safe_workspace_name(name = "analysis", time_in_name = TRUE)
name |
A desired name for the saved workspace. If no name is provided, the name will be 'analysis'. |
time_in_name |
A logical to indicate whether a timestamp should be included in the workspace's name. |
A safe name for exporting the workspace, as a "character string", and also indicated in a message.
if (FALSE) { library(phdcocktail) get_safe_workspace_name() }
if (FALSE) { library(phdcocktail) get_safe_workspace_name() }
A small, non-exhaustive list of variables that are commonly collected in IBD research. For each variable and its levels, if applicable, publications-ready labels are provided
ibd_data_dict
ibd_data_dict
A data frame with 53 rows and four columns:
Variable name in the 'short', i.e. 'excel', form
Variable name in the publication form
Value name in the 'short', i.e. 'excel', form
Value name in the publication form
'ibd_data1' and 'ibd_data2' are two small datasets containing data collected from IBD patients, more specifically patients with Crohn's disease. 'ibd_data2' is a modified version of 'ibd_data1' by introducing missing and incorrect entries 'L11' into the column 'disease_location'.
ibd_data1 ibd_data2
ibd_data1 ibd_data2
Two data frames with each 30 rows and six columns:
Patient ID
Gender
Disease location
Disease behaviour
C-reactive protein (mg/L)
Faecal calprotectin (ug/g)
Randomly generated data
A table containing proportions and percentages of IBD patients achieving clinical outcomes.
ibd_outcomes
ibd_outcomes
A data frame with eight rows and seven columns:
Outcome type
Assessment timepoint
Number of patients who achieved the outcome
Total number of patients
Proportion of patients who achieved the outcome
Percentage of patients who achieved the outcome
Percentage of patients who achieved the outcome, suffixed with '%'
Identify the most recent saved R workspace
identify_recent_workspace(folder = "output")
identify_recent_workspace(folder = "output")
folder |
The folder in which the workspace need to be identified. |
The most recent saved workspace, as a "character string", and also indicated in a message.
library(phdcocktail) if (FALSE) { identify_recent_workspace() }
library(phdcocktail) if (FALSE) { identify_recent_workspace() }
Plot % of outcomes as bars
plot_bars( data, outcome, proportion, percentage_labelled, achieved, total, x_axis_title = NULL, y_axis_title = "% Patients", legend_title = "Outcome", bar_fill = "Greys", grouping = NULL )
plot_bars( data, outcome, proportion, percentage_labelled, achieved, total, x_axis_title = NULL, y_axis_title = "% Patients", legend_title = "Outcome", bar_fill = "Greys", grouping = NULL )
data |
A data frame containing outcomes data. |
outcome |
Variable containing outcomes to be plotted. |
proportion |
Variable containing proportion of patients who achieved the outcome. |
percentage_labelled |
Variable containing percentage of patients who achieved the outcome, suffixed with '%' label. |
achieved |
Variable containing number of patients who achieved the outcome. |
total |
Variable containing total number of patients. |
x_axis_title |
Title of the x-axis. |
y_axis_title |
Title of the y-axis. |
legend_title |
Title of the legend. |
bar_fill |
Fill color of the bars. |
grouping |
Faceting variable. |
A bar plot of outcome percentages.
if (FALSE) { library(phdcocktail) data(ibd_outcomes, package = "phdcocktail") plot_bars(ibd_outcomes) }
if (FALSE) { library(phdcocktail) data(ibd_outcomes, package = "phdcocktail") plot_bars(ibd_outcomes) }
A custom print method for the 'quantiles_report' class
## S3 method for class 'quantiles_report' print(x, ...)
## S3 method for class 'quantiles_report' print(x, ...)
x |
A data frame of the class 'quantiles_report'. |
... |
Other argument that can be passed to 'print'. |
The function displays the content of the column 'report' in separate lines.
if (FALSE) { library(phdcocktail) summary_data <- report_quantiles(mtcars, summary_vrs = "mpg") print(summary_data) }
if (FALSE) { library(phdcocktail) summary_data <- report_quantiles(mtcars, summary_vrs = "mpg") print(summary_data) }
Recode variables and their values based on a data dictionary
recode_vrs(data, data_dictionary, vrs = NULL, factor = FALSE)
recode_vrs(data, data_dictionary, vrs = NULL, factor = FALSE)
data |
A data frame with raw data. |
data_dictionary |
A data dictionary containing labels for variables and their values. |
vrs |
A character vector specifying variables of which the values need to be recoded. |
factor |
A logical to indicate whether recoded variables need to be converted into ordered factors. |
The input data frame with recoded and labelled variables.
if (FALSE) { library(phdcocktail) data(ibd_data1, package = "phdcocktail") ibd_data_recoded <- recode_vrs( data = ibd_data1, data_dictionary = ibd_data_dict, vrs = c("disease_location", "disease_behaviour", "gender"), factor = TRUE ) }
if (FALSE) { library(phdcocktail) data(ibd_data1, package = "phdcocktail") ibd_data_recoded <- recode_vrs( data = ibd_data1, data_dictionary = ibd_data_dict, vrs = c("disease_location", "disease_behaviour", "gender"), factor = TRUE ) }
Report median-quantiles summaries
report_quantiles(data, summary_vrs, grouping_vrs = NULL)
report_quantiles(data, summary_vrs, grouping_vrs = NULL)
data |
A data frame including numeric variables to be summarized. |
summary_vrs |
A character vector specifying the numeric variables to be summarized. |
grouping_vrs |
A character vector specifying the grouping variables, if any. |
A dataframe of the class 'quantiles_report', containing a 'report' column, which report the 'median (quartile 1-quartile 3)' combinations for each specified numeric variable, at each grouping key.
if (FALSE) { library(phdcocktail) summary_data <- report_quantiles(mtcars, summary_vrs = "mpg") print(summary_data) }
if (FALSE) { library(phdcocktail) summary_data <- report_quantiles(mtcars, summary_vrs = "mpg") print(summary_data) }
Restart R session
start_fresh()
start_fresh()
A clean R session
if (FALSE) { library(phdcocktail) start_fresh() }
if (FALSE) { library(phdcocktail) start_fresh() }