diff --git a/data-raw/ae.R b/data-raw/ae.R index fb1433f..f49094d 100644 --- a/data-raw/ae.R +++ b/data-raw/ae.R @@ -1,14 +1,22 @@ -# from CDISC pilot study ---- +# Datasets: ae, suppae +# Description: Standard AE, SUPPAE datasets from CDISC pilot study + +# Load libraries ----- library(dplyr) library(metatools) library(haven) library(admiral) +# Create ae, suppae ---- raw_ae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ae.xpt?raw=true") # nolint raw_suppae <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/suppae.xpt?raw=true") # nolint ae <- convert_blanks_to_na(raw_ae) suppae <- convert_blanks_to_na(raw_suppae) -# Save dataset ---- -save(ae, file = "data/ae.rda", compress = "bzip2") +# Label dataset ---- +attr(ae, "label") <- "Adverse Events" +attr(suppae, "label") <- "Supplemental Qualifiers for AE" + +# Save datasets ---- +usethis::use_data(ae, overwrite = TRUE) usethis::use_data(suppae, overwrite = TRUE) diff --git a/data-raw/ae_ophtha.R b/data-raw/ae_ophtha.R index c7ddd90..84e9d4c 100644 --- a/data-raw/ae_ophtha.R +++ b/data-raw/ae_ophtha.R @@ -1,18 +1,22 @@ -# Update AE by adding AELAT variable for admiralophtha package +# Dataset: ae_ophtha +# Description: Add ophtha-specific AELAT variable to existing AE dataset + +# Load libraries ----- library(dplyr) library(admiral) library(metatools) library(haven) +# Create ae_ophtha ---- # Start from standard AE dataset from this package - this should be # in the environment already if devtools::load_all() has been run ae_ophtha <- ae -# create possible AELAT values - as collected on CRF ---- +## Create possible AELAT values - as collected on CRF ---- lat <- c("LEFT", "RIGHT", "BOTH") -# create AELAT variable ---- -# with random assignment of lat values where AESOC is "EYE DISORDERS" +## Create AELAT variable ---- +# Use random assignment of lat values where AESOC is "EYE DISORDERS" # Set seed so that result stays the same for each run set.seed(1) @@ -24,7 +28,8 @@ ae_ophtha$AELAT <- if_else(ae_ophtha$AESOC == "EYE DISORDERS", ae_ophtha <- ae_ophtha %>% add_labels(AELAT = "Laterality") +# Label dataset ---- attr(ae_ophtha, "label") <- "Adverse Events" # Save dataset ---- -save(ae_ophtha, file = "data/ae_ophtha.rda", compress = "bzip2") +usethis::use_data(ae_ophtha, overwrite = TRUE) diff --git a/data-raw/cm.R b/data-raw/cm.R index 2657e4e..eef48fe 100644 --- a/data-raw/cm.R +++ b/data-raw/cm.R @@ -1,7 +1,16 @@ -# from CDISC pilot study ---- +# Dataset: cm +# Description: Standard CM dataset from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) + +# Create cm ---- raw_cm <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/cm.xpt?raw=true") # nolint cm <- convert_blanks_to_na(raw_cm) +# Label dataset ---- +attr(cm, "label") <- "Concomitant Medications" + +# Save dataset ---- usethis::use_data(cm, overwrite = TRUE) diff --git a/data-raw/dm.R b/data-raw/dm.R index e35f39f..a109253 100644 --- a/data-raw/dm.R +++ b/data-raw/dm.R @@ -1,11 +1,21 @@ -# from CDISC pilot study ---- +# Datasets: dm, suppdm +# Description: Standard DM, SUPPDM datasets from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) + +# Create dm, suppdm ---- sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint raw_dm <- read_xpt(paste0(sdtm_path, "dm", ".xpt?raw=true")) raw_suppdm <- read_xpt(paste0(sdtm_path, "suppdm", ".xpt?raw=true")) dm <- convert_blanks_to_na(raw_dm) suppdm <- convert_blanks_to_na(raw_suppdm) +# Label dataset ---- +attr(dm, "label") <- "Demographics" +attr(suppdm, "label") <- "Supplemental Qualifiers for DM" + +# Save datasets ---- usethis::use_data(dm, overwrite = TRUE) usethis::use_data(suppdm, overwrite = TRUE) diff --git a/data-raw/ds.R b/data-raw/ds.R index 1ba12ea..83c4466 100644 --- a/data-raw/ds.R +++ b/data-raw/ds.R @@ -1,5 +1,7 @@ -# Update DS by adding DSDECOD=RANDOMIZED rows +# Datasets: ds, suppds +# Description: Standard DS, SUPPDS datasets from CDISC pilot study with added DSDECOD = RANDOMIZED rows +# Load libraries ----- library(dplyr) library(tidyselect) library(labelled) @@ -7,23 +9,26 @@ library(admiral) library(metatools) library(haven) +# Create ds ---- data("dm") sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint raw_ds <- read_xpt(paste0(sdtm_path, "ds", ".xpt?raw=true")) raw_suppds <- read_xpt(paste0(sdtm_path, "suppds", ".xpt?raw=true")) -# Converting blank to NA +## Converting blank to NA ---- dm <- convert_blanks_to_na(dm) ds1a <- convert_blanks_to_na(raw_ds) suppds1a <- convert_blanks_to_na(raw_suppds) -# Creating full DS data +## Creating full DS data ---- ds1a <- ds1a %>% mutate(DSSEQ = as.character(DSSEQ)) ds1 <- combine_supp(ds1a, suppds1a) %>% mutate(DSSEQ = as.numeric(DSSEQ)) -# Creating RANDOMIZED records +dsnames <- names(ds1a) + +## Creating RANDOMIZED records ---- dm1 <- select(dm, c(STUDYID, USUBJID, RFSTDTC)) %>% filter(!is.na(RFSTDTC)) %>% mutate( @@ -41,7 +46,7 @@ dm1 <- select(dm, c(STUDYID, USUBJID, RFSTDTC)) %>% ds2 <- bind_rows(ds1, select(dm1, -c(RFSTDTC))) -# Adding labels +## Adding labels ---- dslab <- var_label(ds1a) var_label(ds2) <- dslab @@ -56,7 +61,15 @@ ds3 <- ds2 %>% ) %>% ungroup() -# Creating SUPPDS +ds4 <- ds3 %>% + select(all_of(dsnames)) + +## Label dataset ---- +attr(ds4, "label") <- "Disposition" + +ds <- ds4 + +# Creating SUPPDS ---- suppds1 <- select(ds3, c("STUDYID", "USUBJID", "DSSEQ", "DOMAIN", "ENTCRIT")) %>% filter(!is.na(ENTCRIT)) @@ -68,38 +81,28 @@ suppds2 <- rename(suppds1, "RDOMAIN" = "DOMAIN") %>% "QNAM" = "ENTCRIT", "QLABEL" = "PROTOCOL ENTRY CRITERIA NOT MET", "QORIG" = "CRF" - ) + ) %>% + select(STUDYID, RDOMAIN, USUBJID, IDVAR, IDVARVAL, QNAM, QLABEL, QVAL, QORIG) -suppds <- select( - suppds2, - c( - STUDYID, RDOMAIN, USUBJID, - IDVAR, IDVARVAL, QNAM, QLABEL, - QVAL, QORIG +## Adding labels ---- +suppds3 <- suppds2 %>% + add_labels( + STUDYID = "Study Identifier", + RDOMAIN = "Related Domain Abbreviation", + USUBJID = "Unique Subject Identifier", + IDVAR = "Identifying Variable", + IDVARVAL = "Identifying Variable Value", + QNAM = "Qualifier Variable Name", + QLABEL = "Qualifier Variable Label", + QVAL = "Data Value", + QORIG = "Origin" ) -) - -admiral_suppds <- suppds %>% add_labels( - STUDYID = "Study Identifier", - RDOMAIN = "Related Domain Abbreviation", - USUBJID = "Unique Subject Identifier", - IDVAR = "Identifying Variable", - IDVARVAL = "Identifying Variable Value", - QNAM = "Qualifier Variable Name", - QLABEL = "Qualifier Variable Label", - QVAL = "Data Value", - QORIG = "Origin" -) - -attr(admiral_suppds, "label") <- "Supplemental Disposition" - -# Creating DS -dsnames <- names(ds1a) -admiral_ds <- select(ds3, all_of(dsnames)) -attr(admiral_ds, "label") <- "Disposition" +## Label dataset ---- +attr(suppds3, "label") <- "Supplemental Qualifiers for DS" + +suppds <- suppds3 -ds <- admiral_ds -suppds <- admiral_suppds -save(ds, file = "data/ds.rda", compress = "bzip2") -save(suppds, file = "data/suppds.rda", compress = "bzip2") +# Save datasets ---- +usethis::use_data(ds, overwrite = TRUE) +usethis::use_data(suppds, overwrite = TRUE) diff --git a/data-raw/ex.R b/data-raw/ex.R index 20d31d1..67a2e6f 100644 --- a/data-raw/ex.R +++ b/data-raw/ex.R @@ -1,7 +1,16 @@ -# from CDISC pilot study ---- +# Dataset: ex +# Description: Standard EX dataset from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) + +# Create ex ---- raw_ex <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ex.xpt?raw=true") # nolint ex <- convert_blanks_to_na(raw_ex) +# Label dataset ---- +attr(ex, "label") <- "Exposure" + +# Save dataset ---- usethis::use_data(ex, overwrite = TRUE) diff --git a/data-raw/ex_ophtha.R b/data-raw/ex_ophtha.R index 7aaeaa2..1321e53 100644 --- a/data-raw/ex_ophtha.R +++ b/data-raw/ex_ophtha.R @@ -1,14 +1,20 @@ +# Dataset: ex_ophtha +# Description: Add ophtha-specific EXLOC, EXLAT variables to existing EX dataset +# and modify EXROUTE, EXDOSFRM, EXDOSFRQ to something eye-related + +# Load libraries ----- library(dplyr) library(tidyselect) + +# Make ex_ophtha dataset data("dm") data("ex") -# Make ex_ophtha dataset ex_ophtha <- dm %>% - # Start by merging on ophtha_dm to use the SUBJID variable + ## Merge on ophtha_dm to use the SUBJID variable ---- select(USUBJID, SUBJID) %>% right_join(ex, by = c("USUBJID"), multiple = "all") %>% - # Create EXLOC & EXLAT, change EXROUTE & EXDOSFRM to something eye-related + ## Create EXLOC & EXLAT, change EXROUTE & EXDOSFRM ---- mutate( EXLOC = "EYE", EXDOSFRM = "INJECTION", @@ -24,12 +30,15 @@ ex_ophtha <- dm %>% "EXENDTC", "EXSTDY", "EXENDY" ) -# Label new variables +## Label new variables ---- attr(ex_ophtha$EXLOC, "label") <- "Location of Dose Administration" attr(ex_ophtha$EXLAT, "label") <- "Laterality" attr(ex_ophtha$EXROUTE, "label") <- "Route of Administration" attr(ex_ophtha$EXDOSFRM, "label") <- "Dose Form" attr(ex_ophtha$EXDOSFRQ, "label") <- "Dose Frequency per Interval" -# Save Dataset -save(ex_ophtha, file = file.path("data", "ex_ophtha.rda"), compress = "bzip2") +# Label dataset ---- +attr(ex_ophtha, "label") <- "Exposure" + +# Save dataset ---- +usethis::use_data(ex_ophtha, overwrite = TRUE) diff --git a/data-raw/lb.R b/data-raw/lb.R index 5ceaa66..0317a43 100644 --- a/data-raw/lb.R +++ b/data-raw/lb.R @@ -1,19 +1,21 @@ -# Update LB by adding percentage differential lab test rows +# Dataset: lb +# Description: Standard LB dataset from CDISC pilot study with added percentage differential lab test rows +# Load libraries ----- library(dplyr) library(haven) library(admiral) +# Create LB ---- sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint raw_lb <- read_xpt(paste0(sdtm_path, "lb", ".xpt?raw=true")) -lb <- raw_lb %>% convert_blanks_to_na() +lb_orig <- raw_lb %>% convert_blanks_to_na() - -# Subset on differential lab tests -lb_diff_abs <- lb %>% +## Subset on differential lab tests ---- +lb_diff_abs <- lb_orig %>% filter(LBTESTCD %in% c("BASO", "EOS", "LYM", "MONO", "NEUT")) -# Subset on a few patients and visits +## Subset on a few patients and visits ---- subject_sub <- lb_diff_abs %>% distinct(USUBJID) %>% head() @@ -24,7 +26,7 @@ lb_sub <- lb_diff_abs %>% VISIT %in% c("SCREENING 1", "WEEK 2") ) -# Create dummy differential lab tests +## Create dummy differential lab tests ---- set.seed(1) rand_diff <- sample(seq(0, 0.5, by = 0.05), replace = T, nrow(lb_sub)) @@ -73,12 +75,13 @@ lb_diff <- lb_sub %>% ) -# Replace original rows with new records -admiral_lb <- lb %>% +## Replace original rows with new records ---- +lb <- lb_orig %>% anti_join(lb_diff, by = c("USUBJID", "VISIT", "LBSEQ")) %>% rbind(lb_diff) -attr(admiral_lb, "label") <- "Laboratory Test Results" +# Label dataset ---- +attr(lb, "label") <- "Laboratory Test Results" -lb <- admiral_lb -save(lb, file = "data/lb.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(lb, overwrite = TRUE) diff --git a/data-raw/mh.R b/data-raw/mh.R index 456869f..acd9e83 100644 --- a/data-raw/mh.R +++ b/data-raw/mh.R @@ -1,24 +1,31 @@ -# Add new variables to MH +# Dataset: mh +# Description: Standard MH dataset from CDISC pilot study with variables MENDTC, MHPRESP, MHOCCUR etc + +# Load libraries ----- library(metatools) library(lubridate) library(haven) library(admiral) library(dplyr) -data("dm") +# CReate mh ---- sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint raw_mh <- read_xpt(paste0(sdtm_path, "mh", ".xpt?raw=true")) -# Convert blank to NA +## Get dm ---- +data("dm") + +## Convert blank to NA ---- dm <- convert_blanks_to_na(dm) %>% select(STUDYID, USUBJID, RFSTDTC, RFENDTC, RFXSTDTC, RFXENDTC) -mh <- convert_blanks_to_na(raw_mh) -# Set seed so that result stays the same for each run +mh_orig <- convert_blanks_to_na(raw_mh) + +## Set seed so that result stays the same for each run ---- set.seed(1) ran_int <- sample.int(400, nrow(raw_mh), replace = TRUE) - -admiral_mh <- mh %>% +## Add new variables ---- +mh1 <- mh_orig %>% # Add MHENDTC mutate(MHENDTC = as.character(as.Date(MHSTDTC) + days(ran_int))) %>% # Add MHPRESP @@ -72,6 +79,9 @@ admiral_mh <- mh %>% MHSTAT = "Completion Status" ) -attr(admiral_mh, "label") <- "Medical History" -mh <- admiral_mh -save(mh, file = "data/mh.rda", compress = "bzip2") +# Label dataset ---- +attr(mh1, "label") <- "Medical History" +mh <- mh1 + +# Save dataset ---- +usethis::use_data(mh, overwrite = TRUE) diff --git a/data-raw/oe_ophtha.R b/data-raw/oe_ophtha.R index b7e23dd..68bb41f 100644 --- a/data-raw/oe_ophtha.R +++ b/data-raw/oe_ophtha.R @@ -1,19 +1,23 @@ -# OE +# Dataset: oe +# Description: Create OE test SDTM dataset for ophthalmology studies +# Load libraries ----- library(dplyr) library(metatools) library(tidyselect) library(admiral) -# Read in data +# Create OE ---- + +## Read in data ---- data("dm") data("sv") -# Convert blank to NA +## Convert blank to NA ---- dm <- convert_blanks_to_na(dm) sv <- convert_blanks_to_na(sv) -# set seed to get same results each run +## set seed to get same results each run ----- set.seed(999) oe1 <- select(sv, c(STUDYID, USUBJID, VISIT, VISITNUM, VISITDY, SVSTDTC)) %>% @@ -24,7 +28,7 @@ oe2 <- merge(dm, oe1, by = c("STUDYID", "USUBJID")) oestat <- sample(1:100, nrow(oe2) * 2, replace = TRUE) -# BCVA - Visual Acuity Score +## BCVA - Visual Acuity Score ---- oe31 <- bind_rows( (oe2 %>% mutate("OELAT" = "LEFT")), (oe2 %>% mutate("OELAT" = "RIGHT")) @@ -40,7 +44,7 @@ oe31 <- bind_rows( "OEMETHOD" = "ETDRS EYE CHART" ) -# DRSS +## DRSS ----- oe32 <- bind_rows( (oe2 %>% mutate("OELAT" = "LEFT")), (oe2 %>% mutate("OELAT" = "RIGHT")) @@ -58,7 +62,7 @@ oe32 <- bind_rows( "OEMETHOD" = "COLOR FUNDUS PHOTOGRAPH" ) -# IOP +## IOP ----- oe33 <- bind_rows( (oe2 %>% mutate("OELAT" = "LEFT")), (oe2 %>% mutate("OELAT" = "RIGHT")) @@ -77,7 +81,7 @@ oe33 <- bind_rows( "OEMETHOD" = "APPLANATION TONOMETRY" ) -# CST - Central Subfield Thickness +## CST - Central Subfield Thickness ---- oe34 <- bind_rows( (oe2 %>% mutate("OELAT" = "LEFT")), (oe2 %>% mutate("OELAT" = "RIGHT")) @@ -97,6 +101,7 @@ oe34 <- bind_rows( "OEMETHOD" = "SD-OCT" ) +## Bind all tests ---- oe4 <- bind_rows(oe31, oe32, oe33, oe34) %>% arrange(STUDYID, USUBJID, VISITNUM, OEDTC, OETESTCD, OELAT) %>% group_by(STUDYID, USUBJID) %>% @@ -108,6 +113,7 @@ oe4 <- bind_rows(oe31, oe32, oe33, oe34) %>% "OETPTNUM" = NA ) +## Select columns and add labels ----- oe_ophtha <- oe4 %>% select( STUDYID, DOMAIN, USUBJID, OESEQ, OECAT, OESCAT, OEDTC, VISIT, VISITNUM, VISITDY, @@ -144,5 +150,5 @@ oe_ophtha <- oe4 %>% attr(oe_ophtha, "label") <- "Ophthalmic Examinations" - -save(oe_ophtha, file = "data/oe_ophtha.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(oe_ophtha, overwrite = TRUE) diff --git a/data-raw/pc.R b/data-raw/pc.R index 4b7cd6c..413d630 100644 --- a/data-raw/pc.R +++ b/data-raw/pc.R @@ -1,25 +1,29 @@ -library(haven) # Load xpt +# Dataset: PC +# Description: Create PC test SDTM dataset + +# Load libraries ---- +library(haven) library(plyr) -library(dplyr) # apply distincts +library(dplyr) library(lubridate) library(labelled) library(admiral) +# Create pc ---- data("ex") data("dm") -# set seed to get same results each run +## set seed to get same results each run ---- set.seed(999) -# Remove screen failures, they will not make it to drug infusion +## Remove screen failures, they will not make it to drug infusion ---- dm1 <- dm %>% filter(ARMCD != "Scrnfail") -# use subjects in both datasets (ex,dm1) to create pc +## use subjects in both datasets (ex,dm1) to create pc ---- dmex <- merge(dm1[, c(1, 3)], ex, by = c("STUDYID", "USUBJID")) -# I'm going to calculate only PC on Baseline, -# so going to filter only visit = BASELINE +## Calculate only PC on Baseline, so filter only visit = BASELINE ---- dmex1 <- dmex %>% filter(VISIT == "BASELINE") @@ -39,7 +43,7 @@ noise <- runif(n = nrows, min = -0.05, max = 0.05) dmex1$K <- 0.7 + noise dmex1$V <- dmex1$EXDOSE / (dmex1$K) -# init dataset +## Start setting up dataset PC <- NULL for (t0 in t) { dmex1$t <- t0 @@ -68,7 +72,7 @@ for (t0 in t) { } } -# Constant var +## Constant vars ---- PC$DOMAIN <- "PC" PC$PCTESTCD <- "XAN" PC$PCTEST <- "XANOMELINE" @@ -79,36 +83,36 @@ PC$PCSPEC <- "PLASMA" PC$PCLLOQ <- 0.01 PC$PCTPTNUM <- PC$t -# PCSEQ; +## PCSEQ; ---- PC <- PC %>% group_by(STUDYID, USUBJID) %>% dplyr::mutate(PCSEQ = row_number()) -# Concentration related -# Remove neg values due to pre-dose negative time +## Concentration-related code ---- +### Remove neg values due to pre-dose negative time ---- PC$Conc <- ifelse(PC$Conc < 0, 0, PC$Conc) - PC$PCSTRESN <- PC$Conc -# Usually as per SAP, only predose BLQ can be set to 0 +## Usually as per SAP, only predose BLQ can be set to 0 ---- PC$PCSTRESN <- ifelse(PC$PCSTRESN < 0.01 & PC$t == -0.5, 0, PC$PCSTRESN) # otherwise set it to missing PC$PCSTRESN <- ifelse(PC$PCSTRESN < 0.01 & PC$t != -0.5, NA, PC$PCSTRESN) -# set blqs if NA +## set blqs if NA ---- PC$Conc <- ifelse(PC$Conc < 0.01, "% ungroup() %>% arrange(STUDYID, USUBJID, PCSEQ) -# add labels +## add labels ---- pc <- pc %>% set_variable_labels( STUDYID = "Study Identifier", @@ -150,7 +157,13 @@ pc <- pc %>% PCTPTNUM = "Planned Time Point Number" ) +## Test to look the overall figure ---- +plot <- ggplot(pc, aes(x = PCTPTNUM, y = PCSTRESN, group = USUBJID)) + + geom_line() + + geom_point() +# Label dataset ---- +attr(pc, "label") <- "Pharmacokinetics Concentrations" -# ---- Save output ---- -save(pc, file = "data/pc.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(pc, overwrite = TRUE) diff --git a/data-raw/pp.R b/data-raw/pp.R index c75c5f6..ed8ff7d 100644 --- a/data-raw/pp.R +++ b/data-raw/pp.R @@ -1,29 +1,34 @@ -library(haven) # Load xpt -library(dplyr) # apply distincts +# Dataset: PP +# Description: Create PP test SDTM dataset + +# Load libraries ---- +library(haven) +library(dplyr) library(lubridate) library(labelled) library(admiral) +# Create pc ---- data("pc") -# Calculate subjects with all missing; +## Calculate subjects with all missing ---- blq_usubjid <- pc %>% ungroup() %>% group_by(STUDYID, DOMAIN, USUBJID) %>% summarise(PPORRES = max(PCSTRESN, na.rm = TRUE)) -# Remove from PC, subjects with all blq (placebos); +## Remove from PC, subjects with all blq (placebos) ---- remove_usubjid <- blq_usubjid %>% filter(PPORRES == 0) pc1 <- anti_join(pc, remove_usubjid, by = c("STUDYID", "DOMAIN", "USUBJID")) # PP usually only present values for applicable subjects; -# Calculate Cmax; +## Calculate Cmax ---- pp_cmax <- pc1 %>% group_by(STUDYID, DOMAIN, USUBJID) %>% summarise(CMAX = max(PCSTRESN, na.rm = TRUE)) -# Calculate Tmax +## Calculate Tmax ---- pp_tmax <- pc1 %>% group_by(STUDYID, DOMAIN, USUBJID) %>% filter(PCSTRESN == max(PCSTRESN, na.rm = TRUE)) %>% @@ -31,7 +36,7 @@ pp_tmax <- pc1 %>% pp_tmax$TMAX <- pp_tmax$PCTPTNUM pp_tmax <- subset(pp_tmax, select = c("STUDYID", "DOMAIN", "USUBJID", "TMAX")) -# AUC 0_tlast +## AUC 0_tlast ---- pc2 <- pc1 pc2$PCTPTNUM <- ifelse(pc1$PCTPTNUM == -0.5, 0, pc1$PCTPTNUM) pc2 <- pc2 %>% @@ -60,7 +65,7 @@ pp_npts <- pc3 %>% group_by(STUDYID, DOMAIN, USUBJID) %>% summarise(npts = n()) -# Break up pc3 by usubjid, then fit the specified model to each piece and +## Break up pc3 by usubjid, then fit the specified model to each piece ---- # return a list models <- plyr::dlply(pc3, c("STUDYID", "DOMAIN", "USUBJID"), function(df) { lm(-log(PCSTRESN, base = exp(1)) ~ PCTPTNUM, data = df) @@ -73,12 +78,12 @@ pp_Ke$Ke <- pp_Ke$PCTPTNUM pp_Ke <- subset(pp_Ke, select = c("STUDYID", "DOMAIN", "USUBJID", "Ke")) -# Halflife +## Halflife ---- pp_lambda <- pp_Ke pp_lambda$lambda <- 0.693 / pp_lambda$Ke pp_lambda <- subset(pp_lambda, select = c("STUDYID", "DOMAIN", "USUBJID", "lambda")) -# AUC_0_inf +## AUC_0_inf ---- pc4 <- pc3 %>% group_by(STUDYID, DOMAIN, USUBJID) %>% mutate(min = min(PCSTRESN, na.rm = TRUE)) @@ -93,8 +98,7 @@ pp_AUC_inf <- merge(pc5, pp_AUC, by = c("STUDYID", "DOMAIN", "USUBJID")) pp_AUC_inf$AUC_inf <- pp_AUC_inf$AUC + (pp_AUC_inf$min) / pp_AUC_inf$Ke pp_AUC_inf <- subset(pp_AUC_inf, select = c("STUDYID", "DOMAIN", "USUBJID", "AUC_inf")) -# Add all require variables - +## Add all require variables ----- pp_AUC$PPTESTCD <- "AUCLST" pp_AUC$PPTEST <- "AUC to Last Nonzero Conc" pp_AUC$PPORRESU <- "h*ug/ml" @@ -136,7 +140,7 @@ pp_tmax$PPORRESU <- "h" pp_tmax$PPORRES <- pp_tmax$TMAX # R2ADJ C85553 R Squared Adjusted -# Join all data +## Join all data ---- PP <- bind_rows(pp_tmax, pp_npts, pp_lambda, pp_Ke, pp_cmax, pp_Clast, pp_AUC, pp_AUC_inf) # Constant variables @@ -147,35 +151,36 @@ PP$PPSTRESU <- PP$PPORRESU PP$PPSPEC <- "PLASMA" PP$DOMAIN <- "PP" -# Sort +## Sort ---- pp <- PP %>% arrange(STUDYID, USUBJID, PPTESTCD) -# PPSEQ; +## PPSEQ ---- pp <- pp %>% group_by(STUDYID, USUBJID) %>% mutate(PPSEQ = row_number()) -# Load ex to add the reference time (EXSTDTC) +## Load ex to add the reference time (EXSTDTC) ---- data("ex") -# we only used baseline +## Only use baseline ---- ex1 <- ex %>% filter(VISIT == "BASELINE") -# Select needed vars +## Select needed exvars ---- ex2 <- subset(ex1, select = c("STUDYID", "USUBJID", "EXSTDTC")) -# merge +## Merge pp and ex ---- pp <- merge(pp, ex2, by = c("STUDYID", "USUBJID")) pp$PPRFDTC <- pp$EXSTDTC +## Subset pp vars ----- pp <- subset(pp, select = c( "STUDYID", "DOMAIN", "USUBJID", "PPSEQ", "PPTESTCD", "PPTEST", "PPCAT", "PPORRES", "PPORRESU", "PPSTRESC", "PPSTRESN", "PPSTRESU", "PPSPEC", "PPRFDTC" )) -# add labels +# Label pp ---- pp <- pp %>% set_variable_labels( STUDYID = "Study Identifier", @@ -194,7 +199,8 @@ pp <- pp %>% PPRFDTC = "Date/Time of Reference Point" ) +# Label dataset ---- +attr(pp, "label") <- "Pharmacokinetics Parameters" - -# ---- Save output ---- -save(pp, file = "data/pp.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(pp, overwrite = TRUE) diff --git a/data-raw/qs_ophtha.R b/data-raw/qs_ophtha.R index d24df94..be4cea6 100644 --- a/data-raw/qs_ophtha.R +++ b/data-raw/qs_ophtha.R @@ -1,21 +1,23 @@ +# Dataset: qs +# Description: Create QS test SDTM dataset with VFQ records for ophthalmology studies + +# Load libraries ----- library(dplyr) library(stringr) library(metatools) library(haven) library(admiral) - -# from CDISC pilot study ---- +# Create qs_ophtha ---- +## Get qs from CDISC pilot study ---- sdtm_path <- "https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/" # nolint raw_qs <- read_xpt(paste0(sdtm_path, "qs", ".xpt?raw=true")) %>% convert_blanks_to_na() - -# set seed to get same results each run +## set seed to get same results each run ---- set.seed(999) -# add vfq data -# create new QS data - keep standard variables from previous ADMIRAL project's QS ==== +## add VFQ data ---- qs1 <- raw_qs %>% # select standard variables select(STUDYID, DOMAIN, USUBJID, QSBLFL, VISITNUM, VISIT, VISITDY, QSDTC, QSDY) %>% @@ -23,7 +25,7 @@ qs1 <- raw_qs %>% group_by(USUBJID, VISITDY) %>% unique() -# create dummy parameters and results ==== +#### create dummy parameters and results ---- dummy_param <- data.frame(QSTEST = c( "Your Overall Health Is", "Eyesight Using Both Eyes Is", @@ -61,7 +63,7 @@ dummy_param <- data.frame(QSTEST = c( QSSCAT = "Original Response" ) -# dummy answers +### dummy answers ---- # difficulty in performing tasks difficulty_res <- c( @@ -90,7 +92,7 @@ yesno <- setNames(yn_res, yn_resn) answers <- c(difficulty_res, freq_res, qual_res, yn_res) answersn <- c(difficulty_resn, freq_resn, qual_resn, yn_resn) -# assign answers to questions randomly for each subjects +### assign answers to questions randomly for each subjects ---- # take unique subjects subjects <- qs1 %>% @@ -114,7 +116,7 @@ dummy_param_res_by_subj <- merge(subjects, dummy_param) %>% QSDRVFL = "" ) -# merge standard QS with parameters and result variables from temp QS data +### Merge standard QS with parameters and result variables from ophtha QS data ---- qs2 <- merge(qs1, dummy_param_res_by_subj, by = "USUBJID") %>% group_by(USUBJID) %>% @@ -132,14 +134,12 @@ qs3 <- qs2 %>% ) %>% ungroup() -# NOTE: the QS2 dataset made above should be stacked below the qs dataset. -# output qs_ophtha.RDS -# remove the original vfq part from admiral_qs -admiral_qs_novfq <- raw_qs %>% filter(QSCAT != "NEI VFQ-25") +## Keep only VFQ records ---- +qs_novfq <- raw_qs %>% filter(QSCAT != "NEI VFQ-25") -qs_ophtha1 <- rbind(admiral_qs_novfq, qs3) +qs_ophtha1 <- rbind(qs_novfq, qs3) -# --SEQ and keep relevant variables; +## xxSEQ and keep relevant variables ---- qs_ophtha2 <- qs_ophtha1 %>% select(-QSSEQ) %>% arrange(STUDYID, USUBJID, QSCAT, QSTESTCD, QSDTC, VISITNUM) @@ -155,9 +155,8 @@ qs_ophtha3 <- qs_ophtha2 %>% qs_ophtha <- qs_ophtha3 -# assign dataset label +# Assign dataset label ---- attr(qs_ophtha, "label") <- "Questionnaires" -# ---- Save output for temporary usage ---- -# save(qs_ophtha, file = "data/qs_ophtha.rda", compress = "bzip2") +# Save dataset ---- usethis::use_data(qs_ophtha, overwrite = TRUE) diff --git a/data-raw/query_databases.R b/data-raw/query_databases.R index 8b99388..2f61e61 100644 --- a/data-raw/query_databases.R +++ b/data-raw/query_databases.R @@ -1,5 +1,10 @@ +# Dataset: sdg_db, smq_db +# Description: Create example SDG, SMQ dataset + +# Load libraries ---- library(dplyr) +# Create smq dataset ---- pregsmq <- tribble( ~termname, ~scope, "Achromotrichia congenital", "narrow", @@ -65,9 +70,13 @@ smq_db <- bind_rows(pregsmq, bilismq) %>% termvar = "AEDECOD" ) -# admiral_smq_db <- smq_db -save(smq_db, file = "data/smq_db.rda", compress = "bzip2") +# Label dataset ---- +attr(smq_db, "label") <- "SMQ" + +# Save smq dataset ---- +usethis::use_data(smq_db, overwrite = TRUE) +# Create sdg dataset ---- sdg_db <- tribble( ~termname, "AMINOSALICYLIC ACID", @@ -94,4 +103,8 @@ sdg_db <- tribble( version = "2019-09" ) -save(sdg_db, file = "data/sdg_db.rda", compress = "bzip2") +# Label dataset ---- +attr(sdg_db, "label") <- "SDG" + +# Save sdg dataset ---- +usethis::use_data(sdg_db, overwrite = TRUE) diff --git a/data-raw/rs_onco.R b/data-raw/rs_onco.R index dae7c64..2a64bf8 100644 --- a/data-raw/rs_onco.R +++ b/data-raw/rs_onco.R @@ -1,15 +1,20 @@ -# RS -# Please note that tr.R should run first +# Dataset: rs +# Description: RS test SDTM dataset for Oncology studies +# Please note that tr_onco.R should run first + +# Load libraries ----- library(dplyr) library(tidyselect) library(admiral) library(metatools) -# Reading input data +# Create rs ---- + +## Read input data ---- data("tr_onco") -# Converting blank to NA +## Convert blank to NA ---- tr <- convert_blanks_to_na(tr_onco) keyvar <- c( @@ -17,7 +22,7 @@ keyvar <- c( "TRDTC", "VISIT", "VISITNUM", "TRDY", "TRACPTFL" ) -# Deriving PCHG +## Derive PCHG ---- sumdiam1 <- tr %>% filter(TRTESTCD == "SUMDIAM") %>% select(., c(all_of(keyvar), TRLNKGRP, TRSTRESN, TRSTAT, TRREASND)) @@ -32,7 +37,7 @@ sumdiam <- left_join(sumdiam1, sumb, ) %>% mutate("PCHG" = (TRSTRESN - BASE) * 100 / BASE) -# Dummy Data Nadir Not Used In PD Derivation (>5 mm and 20% increase from nadir) +## Dummy Data Nadir Not Used In PD Derivation (>5 mm and 20% increase from nadir) ---- trgresp <- sumdiam %>% mutate( "TRGRESP" = case_when( !is.na(PCHG) & PCHG <= -100 ~ "CR", @@ -46,7 +51,7 @@ trgresp <- sumdiam %>% mutate( "TRTESTCD" = "TRGRESP" ) -# Select Non-target Response Per Visit +## Select Non-target Response Per Visit ---- ntar <- tr %>% filter(TRTESTCD == "TUMSTATE" & TRGRPID == "NON-TARGET") %>% select(., c(all_of(keyvar), TRORRES, TRREASND)) %>% @@ -73,7 +78,7 @@ ntrgresp <- ntar %>% mutate( "TRTESTCD" = "NTRGRESP" ) -# Select New Lesions Per Visit +## Select New Lesions Per Visit ---- nle <- tr %>% filter(TRTESTCD == "TUMSTATE" & TRGRPID == "NEW") %>% select(., c(all_of(keyvar), TRORRES)) %>% @@ -93,11 +98,11 @@ newlprog <- nle %>% mutate( "TRTESTCD" = "NEWLPROG" ) -# Merging All Visit Level Data +## Merge All Visit Level Data ---- rs1 <- full_join(trgresp, ntrgresp, by = c(all_of(keyvar))) rs2 <- full_join(rs1, newlprog, by = c(all_of(keyvar))) -# Deriving Overall Response +## Derive Overall Response ---- ovrlresp <- rs2 %>% filter(VISITNUM > 3) %>% mutate( @@ -132,7 +137,7 @@ ovrlresp <- rs2 %>% ) ) -# Setting All Data And Adding Other Variables +## Set All Data And Add Other Variables ---- rs5 <- bind_rows( select(trgresp, c(all_of(keyvar), "TRREASND", "TRTESTCD", "TRGRESP")) %>% rename("RSORRES" = "TRGRESP"), @@ -170,7 +175,7 @@ rs5 <- bind_rows( "RSSTAT" = case_when(!is.na(RSREASND) ~ "NOT DONE") ) -# RSSEQ +## RSSEQ ---- rs6 <- rs5 %>% arrange( STUDYID, USUBJID, VISITNUM, RSDTC, @@ -180,7 +185,7 @@ rs6 <- rs5 %>% mutate(RSSEQ = row_number()) %>% ungroup() -# Creating RS +## Create labels and final dataset ---- rs <- select(rs6, c( STUDYID, DOMAIN, USUBJID, RSSEQ, RSLNKGRP, RSTESTCD, RSTEST, RSCAT, RSORRES, RSSTRESC, @@ -210,6 +215,8 @@ rs_onco <- rs %>% add_labels( RSDY = "Study Day of Response Assessment" ) -attr(rs_onco, "label") <- "Disease Response" +# Label dataset ---- +attr(rs_onco, "label") <- "Disease Response and Clin Classification" -save(rs_onco, file = "data/rs_onco.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(rs_onco, overwrite = TRUE) diff --git a/data-raw/sc_ophtha.R b/data-raw/sc_ophtha.R index 5c11f9c..f2d599e 100644 --- a/data-raw/sc_ophtha.R +++ b/data-raw/sc_ophtha.R @@ -1,24 +1,26 @@ -# SC (ophthalmology) +# Dataset: sc +# Description: Create SC test SDTM dataset for ophthalmology studies +# Load libraries ----- library(dplyr) library(metatools) +# Create sc ---- +## Load required datasets ---- data("dm") data("sv") - -# Remove screen failures, they will not make it to drug infusion +## Remove screen failures, they will not make it to drug infusion --- dm1 <- dm %>% filter(ARMCD != "Scrnfail") - -# Use subjects in DM and info from SV Screening 1 visit +## Use subjects in DM and info from SV Screening 1 visit --- sc <- merge(dm1[, c("STUDYID", "USUBJID", "SUBJID", "RFSTDTC")], sv[sv$VISIT == "SCREENING 1", c("STUDYID", "USUBJID", "SVSTDTC", "VISIT")], by = c("STUDYID", "USUBJID") ) -# Create SC domain var +## Create SC domain vars ---- sc$DOMAIN <- "SC" sc$SCCAT <- "STUDY EYE SELECTION" sc$SCTESTCD <- "FOCID" @@ -30,8 +32,7 @@ sc$SCDY <- as.numeric(as.Date(sc$SCDTC) - as.Date(sc$RFSTDTC)) sc$SCORRES <- if_else(as.integer(sc$SUBJID) %% 2 == 0, "Left Eye", "Right Eye") sc$SCSTRESC <- if_else(as.integer(sc$SUBJID) %% 2 == 0, "OS", "OD") - -# SCSEQ and keep relevant variables; +## Create SCSEQ and keep relevant variables ---- sc_seq <- sc %>% group_by(STUDYID, USUBJID) %>% mutate(SCSEQ = row_number()) %>% @@ -40,6 +41,7 @@ sc_seq <- sc %>% "SCCAT", "SCORRES", "SCSTRESC", "EPOCH", "SCDTC", "SCDY" ) +## Sort and variable labels ----- sc_ophtha <- sc_seq %>% ungroup() %>% # Sort data @@ -60,9 +62,8 @@ sc_ophtha <- sc_seq %>% SCDY = "Study Day of Examination" ) - -# assign dataset label +# Dataset label ---- attr(sc_ophtha, "label") <- "Subject Characteristic" -# Save output -save(sc_ophtha, file = "data/sc_ophtha.rda", compress = "bzip2") +# Save dataset +usethis::use_data(sc_ophtha, overwrite = TRUE) diff --git a/data-raw/sv.R b/data-raw/sv.R index 8313e0c..3a40165 100644 --- a/data-raw/sv.R +++ b/data-raw/sv.R @@ -1,7 +1,14 @@ -# from CDISC pilot study ---- +# Dataset: sv +# Description: StandardSV dataset from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) raw_sv <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/sv.xpt?raw=true") # nolint sv <- convert_blanks_to_na(raw_sv) +# Label dataset ---- +attr(sv, "label") <- "Subject Visits" + +# Save dataset ---- usethis::use_data(sv, overwrite = TRUE) diff --git a/data-raw/tr_onco.R b/data-raw/tr_onco.R index 1028fb4..44036b4 100644 --- a/data-raw/tr_onco.R +++ b/data-raw/tr_onco.R @@ -1,24 +1,29 @@ -# TR +# Dataset: tr, supptr +# Description: TR, SUPPTR test SDTM datasets for Oncology studies +# Load libraries ---- library(dplyr) library(tidyselect) library(metatools) library(admiral) library(metatools) +# Create tr ---- + +## Set seed to obtain reproducible results ----- set.seed(1) -# Reading input data ---- +## Read input data ---- data("dm") data("suppdm") data("sv") -# Converting blank to NA +## Converting blank to NA ---- dm <- convert_blanks_to_na(dm) suppdm <- convert_blanks_to_na(suppdm) sv <- convert_blanks_to_na(sv) -# Creating data frame with visits ---- +## Create data frame with visits ---- dm1 <- dm %>% combine_supp(suppdm) @@ -30,7 +35,7 @@ tr1 <- select(sv, c(STUDYID, USUBJID, VISIT, VISITNUM, VISITDY, SVSTDTC)) %>% tr2 <- merge(dm2, tr1, by = c("STUDYID", "USUBJID")) -# Creating dummy tumors ---- +## Create dummy tumors ---- trloc <- c( "ABDOMINAL CAVITY", "ADRENAL GLAND", "LYMPH NODE", "BLADDER", "BODY", "BONE", "BREAST", "CHEST", "COLON", @@ -44,13 +49,12 @@ trloc <- c( ttyped <- as.data.frame(trloc) %>% rename("TRLOC" = "trloc") ttyped$tar1 <- as.double(row.names(ttyped)) -# Adding records for TARGET, NON-TARGET and NEW LESIONS and -# Selecting Tumor Locations Randomly +## Add records for TARGET, NON-TARGET and NEW LESIONS and Select Tumor Locations Randomly ---- nrows <- dim(tr2)[1] tar <- floor(runif(n = nrows, min = 1, max = 5)) new <- floor(runif(n = nrows, min = 21, max = 22)) -# Target Tumors +## Target Tumors ---- tr3a <- bind_rows( (tr2 %>% mutate("tar1" = tar, "TRLNKID" = "T01")), (tr2 %>% mutate("tar1" = tar + 1, "TRLNKID" = "T02")), @@ -95,7 +99,7 @@ tr3c <- bind_rows( tr3 <- bind_rows(tr3a, tr3b, tr3c) %>% left_join(ttyped, by = "tar1") -# Adding Diameter Values Randomly ---- +## Adding Diameter Values Randomly ---- trows <- dim(tr3)[1] diam <- floor((runif(n = trows, min = 5, max = 15))) @@ -105,7 +109,7 @@ tr3 <- tr3 %>% SUBJNO = as.numeric(substr(USUBJID, 8, 12)) ) -# Modifying Diameter Values To Get Some CR And NE In Target Response Data +## Modifying Diameter Values To Get Some CR And NE In Target Response Data ---- tr3 <- tr3 %>% mutate( "TRSTRESN" = case_when( floor(SUBJNO %% 5) == 0 & VISITNUM %in% c(9, 10.1) ~ 0, @@ -127,7 +131,7 @@ tr3 <- tr3 %>% mutate( "TRTEST" = "Diameter" ) -# Adding LDIAM and LPERP ---- +## Adding LDIAM and LPERP ---- tr3ldiam <- tr3 %>% mutate( TRSTRESN = if_else( TRLOC == "LYMPH NODE", @@ -152,7 +156,7 @@ tr3lperp <- tr3 %>% mutate( TRTEST = "Longest Perpendicular" ) -# SUMDIAM ---- +## SUMDIAM ---- tr3sum <- tr3 %>% group_by( STUDYID, USUBJID, VISITNUM, VISIT, TREVAL, @@ -167,8 +171,7 @@ tr3sum <- tr3 %>% "TRSTRESC" = TRORRES ) -# Non-target Tumors ---- - +## Non-target Tumors ---- ntar <- floor(runif(n = nrows, min = 11, max = 15)) ntr3a <- bind_rows( (tr2 %>% mutate("tar1" = ntar, "TRLNKID" = "NT01")), @@ -207,7 +210,7 @@ ntr3c <- bind_rows( ntr3 <- bind_rows(ntr3a, ntr3b, ntr3c) -# Adding Non Target Result Values Randomly +## Adding Non Target Result Values Randomly ---- ntrorresf <- c("NOT", "UNEQUIVOCAL", "ABSENT", "PRESENT") ntrespd <- tibble::tibble(ntrorresf) @@ -231,14 +234,14 @@ ntr3 <- merge(ntr3, ntrespd, by = "ntresn") %>% "SUBJNO" = as.numeric(substr(USUBJID, 8, 12)) ) -# Modifying Non-target Values To Get Some CR In Data +## Modifying Non-target Values To Get Some CR In Data ---- ntr3 <- ntr3 %>% mutate( "TRORRES" = ifelse(floor(SUBJNO %% 5) == 0 & VISITNUM %in% c(9, 10.1), "ABSENT", TRORRES), "TRSTRESC" = TRORRES ) -# New Lesions - assigning new lesions only on last visit +## New Lesions - assigning new lesions only on last visit ---- new <- floor(runif(n = nrows, min = 21, max = 22)) new3a <- tr2 %>% mutate( "tar1" = new, @@ -279,7 +282,7 @@ new3 <- bind_rows(new3a, new3b, new3c) %>% ) %>% filter(VISITNUM > 3 & (TRORRES != "NO")) -# Setting All Tumor Data ---- +## Setting All Tumor Data ---- tr <- bind_rows( tr3 %>% filter(EFFICACY == "Y" | (SAFETY == "Y" & VISITNUM == 3)), tr3ldiam %>% filter(EFFICACY == "Y" | (SAFETY == "Y" & VISITNUM == 3)), @@ -296,7 +299,7 @@ tr <- bind_rows( VISITNUM == 12 ~ "A4" )) -# TRSEQ and Other Variables ---- +## TRSEQ and Other Variables ---- tr <- tr %>% arrange(STUDYID, USUBJID, VISITNUM, TRDTC, TRGRPID, TRLNKID) %>% group_by(STUDYID, USUBJID) %>% @@ -354,9 +357,9 @@ supptr_onco <- supptr %>% add_labels( QORIG = "Origin" ) -attr(supptr_onco, "label") <- "Supplemental Tumor Results" +attr(supptr_onco, "label") <- "Supplemental Qualifiers for TR" -# Creating TR ---- +# Create final TR dataset ---- tr <- select(tr, c( STUDYID, DOMAIN, USUBJID, TRSEQ, TRGRPID, TRLNKGRP, TRLNKID, TRTESTCD, TRTEST, TRORRES, TRORRESU, TRSTRESC, @@ -391,8 +394,9 @@ tr_onco <- tr %>% add_labels( TRDY = "Study Day of Tumor Measurement" ) -attr(tr_onco, "label") <- "Tumor Results" - +# Label TR dataset ---- +attr(tr_onco, "label") <- "Tumor/Lesion Results" -save(tr_onco, file = "data/tr_onco.rda", compress = "bzip2") -save(supptr_onco, file = "data/supptr_onco.rda", compress = "bzip2") +# Save datasets ---- +usethis::use_data(tr_onco, overwrite = TRUE) +usethis::use_data(supptr_onco, overwrite = TRUE) diff --git a/data-raw/ts.R b/data-raw/ts.R index 284414e..ecd41ad 100644 --- a/data-raw/ts.R +++ b/data-raw/ts.R @@ -1,7 +1,14 @@ -# from CDISC pilot study ---- +# Datasets: ts +# Description: Standard TS dataset from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) raw_ts <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/ts.xpt?raw=true") # nolint ts <- convert_blanks_to_na(raw_ts) +# Label dataset ---- +attr(ts, "label") <- "Trial Summary Information" + +# Save dataset ----- usethis::use_data(ts, overwrite = TRUE) diff --git a/data-raw/tu_onco.R b/data-raw/tu_onco.R index 6eaeb4e..719c9c9 100644 --- a/data-raw/tu_onco.R +++ b/data-raw/tu_onco.R @@ -1,12 +1,17 @@ -# TU -# Please note that tr.R should run first +# Dataset: tu +# Description: TU test SDTM dataset for Oncology studies +# Please note that tr_onco.R should run first + +# Load libraries ---- library(dplyr) library(tidyselect) library(admiral) library(metatools) -# Reading input data -- DUMMY DATA CREATED FROM TR data created from TR + +# Create tu ---- +## Read input data -- DUMMY DATA CREATED FROM TR data created from TR ---- data("tr_onco") data("supptr_onco") @@ -19,7 +24,7 @@ supptr1 <- supptr %>% tr <- full_join(tr, supptr1, by = c("STUDYID", "USUBJID", "TRSEQ")) -# Renaming And Adding TU Variables +## Rename And Add TU Variables ---- tu1 <- tr %>% filter((VISITNUM == 3 | (TRGRPID == "NEW" & !is.na(TRORRES) & TRORRES != "NO"))) %>% @@ -43,14 +48,14 @@ tu1 <- tr %>% TUSTRESC = TUORRES ) -# TUSEQ +## TUSEQ ---- tu2 <- tu1 %>% arrange(STUDYID, USUBJID, VISITNUM, TUDTC, TULNKID) %>% group_by(STUDYID, USUBJID) %>% mutate(TUSEQ = row_number()) %>% ungroup() -# Creating TU +## Create TU ---- tu <- select(tu2, c( STUDYID, DOMAIN, USUBJID, TUSEQ, TULNKID, TUTESTCD, TUTEST, TUORRES, TUSTRESC, TULOC, @@ -79,6 +84,8 @@ tu_onco <- tu %>% add_labels( TUDY = "Study Day of Tumor Identification" ) -attr(tu_onco, "label") <- "Tumor Identification" +# Label dataset ---- +attr(tu_onco, "label") <- "Tumor/Lesion Identification" -save(tu_onco, file = "data/tu_onco.rda", compress = "bzip2") +# Save dataset ---- +usethis::use_data(tu_onco, overwrite = TRUE) diff --git a/data-raw/vs.R b/data-raw/vs.R index 748cd25..b5d375f 100644 --- a/data-raw/vs.R +++ b/data-raw/vs.R @@ -1,7 +1,14 @@ -# from CDISC pilot study ---- +# Dataset: vs +# Description: Standard VS dataset from CDISC pilot study + +# Load libraries ----- library(haven) library(admiral) raw_vs <- read_xpt("https://github.com/cdisc-org/sdtm-adam-pilot-project/blob/master/updated-pilot-submission-package/900172/m5/datasets/cdiscpilot01/tabulations/sdtm/vs.xpt?raw=true") # nolint vs <- convert_blanks_to_na(raw_vs) +# Label dataset ---- +attr(vs, "label") <- "Vital Signs" + +# Save dataset ---- usethis::use_data(vs, overwrite = TRUE) diff --git a/data/ae.rda b/data/ae.rda index 359f582..8d45a88 100644 Binary files a/data/ae.rda and b/data/ae.rda differ diff --git a/data/ae_ophtha.rda b/data/ae_ophtha.rda index f40b42b..fbc4fe7 100644 Binary files a/data/ae_ophtha.rda and b/data/ae_ophtha.rda differ diff --git a/data/cm.rda b/data/cm.rda index 77303de..255b982 100644 Binary files a/data/cm.rda and b/data/cm.rda differ diff --git a/data/dm.rda b/data/dm.rda index e88a36f..ed18b11 100644 Binary files a/data/dm.rda and b/data/dm.rda differ diff --git a/data/ds.rda b/data/ds.rda index 47eaa55..f02ed30 100644 Binary files a/data/ds.rda and b/data/ds.rda differ diff --git a/data/ex.rda b/data/ex.rda index 7994907..2c2f880 100644 Binary files a/data/ex.rda and b/data/ex.rda differ diff --git a/data/ex_ophtha.rda b/data/ex_ophtha.rda index aac6568..31d9364 100644 Binary files a/data/ex_ophtha.rda and b/data/ex_ophtha.rda differ diff --git a/data/lb.rda b/data/lb.rda index 64e76c3..7036ab5 100644 Binary files a/data/lb.rda and b/data/lb.rda differ diff --git a/data/mh.rda b/data/mh.rda index c217eeb..24aa242 100644 Binary files a/data/mh.rda and b/data/mh.rda differ diff --git a/data/oe_ophtha.rda b/data/oe_ophtha.rda index b7c77e7..a98c41c 100644 Binary files a/data/oe_ophtha.rda and b/data/oe_ophtha.rda differ diff --git a/data/pc.rda b/data/pc.rda index ee3a87c..da0c1d3 100644 Binary files a/data/pc.rda and b/data/pc.rda differ diff --git a/data/pp.rda b/data/pp.rda index d989ac8..852a978 100644 Binary files a/data/pp.rda and b/data/pp.rda differ diff --git a/data/qs_ophtha.rda b/data/qs_ophtha.rda index 5af228b..708ab88 100644 Binary files a/data/qs_ophtha.rda and b/data/qs_ophtha.rda differ diff --git a/data/rs_onco.rda b/data/rs_onco.rda index 2f9e3a2..34d9bbd 100644 Binary files a/data/rs_onco.rda and b/data/rs_onco.rda differ diff --git a/data/sc_ophtha.rda b/data/sc_ophtha.rda index e90ed2c..91b1fc8 100644 Binary files a/data/sc_ophtha.rda and b/data/sc_ophtha.rda differ diff --git a/data/sdg_db.rda b/data/sdg_db.rda index 5582418..996eeb9 100644 Binary files a/data/sdg_db.rda and b/data/sdg_db.rda differ diff --git a/data/smq_db.rda b/data/smq_db.rda index eff8cab..1a7fc4c 100644 Binary files a/data/smq_db.rda and b/data/smq_db.rda differ diff --git a/data/suppae.rda b/data/suppae.rda index e26bce6..df9f432 100644 Binary files a/data/suppae.rda and b/data/suppae.rda differ diff --git a/data/suppdm.rda b/data/suppdm.rda index 0930b5c..994caa0 100644 Binary files a/data/suppdm.rda and b/data/suppdm.rda differ diff --git a/data/suppds.rda b/data/suppds.rda index b1459fa..4f69813 100644 Binary files a/data/suppds.rda and b/data/suppds.rda differ diff --git a/data/supptr_onco.rda b/data/supptr_onco.rda index 691dfb2..a75231f 100644 Binary files a/data/supptr_onco.rda and b/data/supptr_onco.rda differ diff --git a/data/sv.rda b/data/sv.rda index 9c24293..c24f1cc 100644 Binary files a/data/sv.rda and b/data/sv.rda differ diff --git a/data/tr_onco.rda b/data/tr_onco.rda index 8f153b5..6e1eefc 100644 Binary files a/data/tr_onco.rda and b/data/tr_onco.rda differ diff --git a/data/ts.rda b/data/ts.rda index 9aedee9..36f6fa3 100644 Binary files a/data/ts.rda and b/data/ts.rda differ diff --git a/data/tu_onco.rda b/data/tu_onco.rda index e4b0046..6edbc4e 100644 Binary files a/data/tu_onco.rda and b/data/tu_onco.rda differ diff --git a/data/vs.rda b/data/vs.rda index 3eb7d7d..63051f7 100644 Binary files a/data/vs.rda and b/data/vs.rda differ