This article is an example workflow of the modular approach where each section of the cut is explicitly called.
# Name: Datacut Template Code - Modular Approach
# Creating data to be cut ------------------------------------------------
library(datacutr)
library(admiraldev)
library(dplyr)
library(lubridate)
library(stringr)
library(purrr)
<- list(ds = datacutr_ds, dm = datacutr_dm, ae = datacutr_ae, sc = datacutr_sc, lb = datacutr_lb, fa = datacutr_fa, ts = datacutr_ts)
source_data
# Create DCUT ------------------------------------------------------------
<- create_dcut(
dcut dataset_ds = source_data$ds,
ds_date_var = DSSTDTC,
filter = DSDECOD == "RANDOMIZATION",
cut_date = "2022-06-04",
cut_description = "Clinical Cutoff Date"
)
# Pre-processing of FA ----------------------------------------------------
# Update FA
$fa <- source_data$fa %>%
source_datamutate(DCUT_TEMP_FAXDTC = case_when(
!= "" ~ FASTDTC,
FASTDTC != "" ~ FADTC,
FADTC TRUE ~ as.character(NA)
))
# Specify cut types ------------------------------------------------------
# Patient cut - cut applied will only be for patients existing in DCUT
<- c("sc", "ds")
patient_cut_list
# Date cut - cut applied will be both for patients existing in DCUT, and date cut against DCUTDTM
<- rbind(
date_cut_list c("ae", "AESTDTC"),
c("lb", "LBDTC"),
c("fa", "DCUT_TEMP_FAXDTC")
)
# No cut - data does not need to be cut
<- list(ts = source_data$ts)
no_cut_list
# Create the cutting variables -------------------------------------------
# Conduct the patient cut ------------------------------------------------
<- lapply(
patient_cut_data
source_data[patient_cut_list], pt_cut,dataset_cut = dcut
)
# Conduct xxSTDTC or xxDTC Cut -------------------------------------------
<- pmap(
date_cut_data .l = list(
dataset_sdtm = source_data[date_cut_list[, 1]],
sdtm_date_var = syms(date_cut_list[, 2])
),.f = date_cut,
dataset_cut = dcut,
cut_var = DCUTDTM
)
# Conduct DM special cut for DTH flags after DCUTDTM ---------------------
<- special_dm_cut(
dm_cut dataset_dm = source_data$dm,
dataset_cut = dcut,
cut_var = DCUTDTM
)
# Apply the cut --------------------------------
<- purrr::map(
cut_data c(patient_cut_data, date_cut_data, list(dm = dm_cut)),
apply_cut,dcutvar = DCUT_TEMP_REMOVE,
dthchangevar = DCUT_TEMP_DTHCHANGE
)
# Add on data which is not cut
<- c(cut_data, no_cut_list, list(dcut = dcut)) final_data