Skip to content
/ croquet Public

Miscellaneous operations for PCCTC, a Clinical Research Organization (CRO)

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

pcctc/croquet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6f51003 · Mar 10, 2025

History

90 Commits
Mar 10, 2025
Mar 10, 2025
May 12, 2023
Aug 9, 2024
Jul 30, 2024
Mar 3, 2023
Jan 15, 2023
Jan 17, 2023
Mar 10, 2025
Dec 8, 2021
Dec 8, 2021
Mar 17, 2023
Mar 10, 2025
Mar 21, 2023
Mar 21, 2023
Jan 17, 2023
Jan 17, 2023
Dec 8, 2021

Repository files navigation

croquet

Lifecycle: experimental CRAN status Codecov test coverage R-CMD-check

A collection of clinical research organization (CRO) miscellaneous functions developed for The Prostate Cancer Clinical Trials Consortium (PCCTC).

Installation

⚠️ This package is under active development! Feedback is welcome, consistency is not yet promised.

You can install the development version of croquet from GitHub with:

# install.packages("devtools")
devtools::install_github("pcctc/croquet")

Exporting labelled data to excel

Brief variable names are useful for coding, but might not provide sufficient context for collaborators. Here, we add variable labels data and export those labels to an excel sheet to make content more readily digestible.

Libraries

library(croquet)
library(openxlsx)

# format all date and date time variables in the excel output 
options("openxlsx.dateFormat" = "yyyy-mm-dd")
options("openxlsx.datetimeFormat" = "yyyy-mm-dd")

Example data

dat1 <- tibble::tibble(
  var_1 = 1:3,
  var_2 = LETTERS[1:3],
  var_3 = Sys.Date() - 0:2
  ) %>%
  labelled::set_variable_labels(
    var_1 = "Variable 1 (numeric)",
    var_2 = "Variable 2 (character)",
    var_3 = "Variable 3 (date)"
  )

dat2 <- tibble::tibble(
  var_1 = 4:6,
  var_2 = LETTERS[4:6],
  var_3 = Sys.Date() - 0:2
  ) %>%
  labelled::set_variable_labels(
    var_1 = "Variable 1 (numeric)",
    var_2 = "Variable 2 (character)",
    var_3 = "Variable 3 (date)"
  )

Export single sheet

# initialize workbook
wb <- createWorkbook()

# default settings name sheet by name of input data
add_labelled_sheet(dat1)

# you can rename sheet to something more meaningful
add_labelled_sheet(dat1, "example sheet")

saveWorkbook(wb, "check-wb-1.xlsx")

Export multiple sheets

# create named list
out <- tibble::lst(dat1, dat2)

# initialize workbook
wb <- createWorkbook()

# create labelled sheets from all input data
add_labelled_sheet(out)

saveWorkbook(wb, "check-wb-2.xlsx")
Shows two tabs named dat1 and dat2. Row 1 has light gray italics text and white background; row 2 has a black background and white text.

Screenshot of resulting excel output.

Importing labelled data from excel

Needs more documentation!

This imports a single sheet that assumes variables labels are in row 1 and variable names are row 2. You can optionally specify a regex expression for date_detect to identify variables that should be explicitly imported as a date.

dat <- read_labelled_sheet(
  path = here::here(path, dsn1),
  sheet = "ae_listings",
  date_detect = "cyc1_visdat|cyc2_visdat"
)