diff --git a/R/generate_code.R b/R/generate_code.R index 9af3ecf0..e0f8cc58 100644 --- a/R/generate_code.R +++ b/R/generate_code.R @@ -60,6 +60,34 @@ dm <- admiral::convert_blanks_to_na(dm) cm <- ') +cm_template_suffix <- stringr::str_glue(' +dplyr::mutate( + STUDYID = "test_study", + DOMAIN = "CM", + CMCAT = "GENERAL CONMED", + USUBJID = paste0("test_study", "-", cm_raw_data$PATNUM) +) %>% +derive_seq(tgt_var = "CMSEQ", + rec_vars= c("USUBJID", "CMTRT")) %>% +derive_study_day( + sdtm_in = ., + dm_domain = dm, + tgdt = "CMENDTC", + refdt = "RFXSTDTC", + study_day_var = "CMENDY" +) %>% +derive_study_day( + sdtm_in = ., + dm_domain = dm, + tgdt = "CMSTDTC", + refdt = "RFXSTDTC", + study_day_var = "CMSTDY" +) %>% +dplyr::select("STUDYID", "DOMAIN", "USUBJID", "CMSEQ", "CMTRT", "CMCAT", "CMINDC", + "CMDOSE", "CMDOSTXT", "CMDOSU", "CMDOSFRM", "CMDOSFRQ", "CMROUTE", + "CMSTDTC", "CMENDTC","CMSTDY", "CMENDY", "CMENRTPT", "CMENTPT") +') + #' Check if a variable is character #' #' @param var_in The variable to check. @@ -107,8 +135,11 @@ is_character <- function(var_in) { #' #' # One can use option width to control the width of the code #' # Twenty will almost always place every parameter on a separate line -#' options(width = 20) +#' spec <- read_spec("cm_sdtm_oak_spec_cdash.csv") +#' domain <- "cm" +#' old_width <- options(width = 20) #' generate_code(spec, domain) +#' options(width = old_width) #' } #' generate_code <- function(spec, domain, out_dir = ".") { @@ -123,8 +154,9 @@ generate_code <- function(spec, domain, out_dir = ".") { \(row) generate_one_var_code(spec_domain[row, ]) ) |> unlist() |> - remove_last_pipe() |> + # remove_last_pipe() |> append(cm_template_prefix, after = 0L) |> + append(cm_template_suffix) |> styler::style_text() # Save the code to a file diff --git a/man/generate_code.Rd b/man/generate_code.Rd index ca651ce6..48184b2c 100644 --- a/man/generate_code.Rd +++ b/man/generate_code.Rd @@ -32,8 +32,11 @@ generate_code(spec, domain) # One can use option width to control the width of the code # Twenty will almost always place every parameter on a separate line -options(width = 20) +spec <- read_spec("cm_sdtm_oak_spec_cdash.csv") +domain <- "cm" +old_width <- options(width = 20) generate_code(spec, domain) +options(width = old_width) } }