Skip to content

Commit

Permalink
#107 add suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
edgar-manukyan committed Dec 2, 2024
1 parent 091dc95 commit a187e18
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
36 changes: 34 additions & 2 deletions R/generate_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = ".") {
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion man/generate_code.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a187e18

Please sign in to comment.