#' Load Laboratory Measurements Data
#'
#' This function performs the following operations:
#' * loads the data
#' * casts the variables to their correct types
#' * transforms the variable names to snake case
#' * performs a light touch cleaning by transforming character variables to
#' title case
#'
#' @return a data frame (tibble) containing laboratory measurements data
#' @export
#'
#' @examples
#' \dontrun{
#' lab_data <- load_lab_data()
#' }
load_lab_data <- function() {
folder <- system.file(package = "rocheshiny", "extdata")
lab_file <- file.path(folder, "Random_LabValuesInfo_2020.tsv")
cols_to_title_case_lab <- c("bmrkr2", "lbcat", "avisit")
lab_data <- readr::read_tsv(lab_file,
col_types = readr::cols(
STUDYID = readr::col_character(),
USUBJID = readr::col_character(),
BMRKR1 = readr::col_double(),
BMRKR2 = readr::col_character(),
LBTESTCD = readr::col_character(),
LBTEST = readr::col_character(),
LBCAT = readr::col_character(),
AVAL = readr::col_double(),
AVALU = readr::col_character(),
AVISIT = readr::col_character()
)) %>%
janitor::clean_names() %>%
dplyr::mutate_at(.vars = cols_to_title_case_lab,
.funs = stringr::str_to_title) %>%
dplyr::group_by(.data$usubjid, .data$lbtestcd) %>%
dplyr::mutate(order = dplyr::row_number()) %>%
dplyr::ungroup() %>%
dplyr::mutate(visit = stringr::str_remove_all(.data$avisit,
pattern = "Week [1-5] "))
lab_data
}
#' Load Patient Data
#'
#' Similar to [load_lab_data()] this function performs the following operations:
#' * loads the data
#' * casts the variables to their correct types
#' * transforms the variable names to snake case
#' * performs a light touch cleaning by transforming character variables to
#' title case
#'
#'
#' @return a data frame (tibble) containing patient data
#' @export
#'
#' @examples
#'\dontrun{
#'patient_data <- load_patient_data()
#'}
load_patient_data <- function() {
folder <- system.file(package = "rocheshiny", "extdata")
patient_file <- file.path(folder, "Random_PatientLevelInfo_2020.tsv")
cols_to_title_case_pat <- c("sex", "race")
patient_data <- readr::read_tsv(patient_file,
col_types = readr::cols(
STUDYID = readr::col_character(),
USUBJID = readr::col_character(),
AGE = readr::col_double(),
SEX = readr::col_character(),
RACE = readr::col_character(),
ACTARM = readr::col_character(),
ACTARMCD = readr::col_character()
)) %>%
janitor::clean_names() %>%
dplyr::mutate_at(.vars = cols_to_title_case_pat,
.funs = stringr::str_to_title) %>%
dplyr::mutate(race = stringr::str_replace_all(.data$race, "Or", "or"))
patient_data
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.