diff --git a/.Rbuildignore b/.Rbuildignore index 3ebfe8a954..02dc6bada0 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,5 +1,6 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^\.pre-commit-config\.yaml$ ^temp$ ^.github$ ^staged_dependencies.yaml$ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2bb32ecb99..d55d5df90a 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.2.2.9009 + rev: v0.2.2.9013 hooks: - id: style-files name: Style code with `styler` diff --git a/NAMESPACE b/NAMESPACE index d99bf12622..11b0e9946f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ export(aet03_1) export(aet03_1_lyt) export(aet04_1) export(aet04_1_lyt) -export(append_to_pmap) export(assert_colnames) export(bol_YN) export(cmt01a_1) diff --git a/R/aet01.R b/R/aet01.R index ab576adc96..d56d08cd61 100644 --- a/R/aet01.R +++ b/R/aet01.R @@ -11,14 +11,10 @@ #' @param safety_var (`character`) the safety variables to be summarized. #' @param lbl_safety_var (`character`) the labels of the safety variables to be summarized. #' -#' @importFrom magrittr %>% -#' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' preprocess_data("aet01_1") @@ -66,7 +62,7 @@ aet01_1 <- function(adam_db, tbl <- set_decoration(tbl, deco) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl @@ -80,9 +76,6 @@ aet01_1 <- function(adam_db, #' @param safety_var (`character`) the safety variables to be summarized. #' @param lbl_safety_var (`character`) the labels of the safety variables to be summarized. #' -#' @importFrom magrittr %>% -#' -#' @return #' @export #' #' @examples @@ -110,8 +103,7 @@ aet01_1_lyt <- function(armvar = .study$actualarm, )) { names(lbl_safety_var) <- safety_var - lyt_adae <- - basic_table_deco(deco) %>% + lyt_adae <- basic_table_deco(deco) %>% split_cols_by(var = armvar) %>% add_colcounts() %>% ifneeded_add_overall_col(lbl_overall) %>% @@ -133,8 +125,7 @@ aet01_1_lyt <- function(armvar = .study$actualarm, .indent_mods = 0L ) - lyt_adsl <- - basic_table_deco(deco) %>% + lyt_adsl <- basic_table_deco(deco) %>% split_cols_by(var = armvar) %>% add_colcounts() %>% ifneeded_add_overall_col(lbl_overall) %>% @@ -172,9 +163,6 @@ aet01_1_lyt <- function(armvar = .study$actualarm, #' @param medconcept_var (`character`) the medical concept variables to be summarized. #' @param lbl_medconcept_var (`character`) the label of the medical concept variables to be summarized. #' -#' @importFrom magrittr %>% -#' -#' @return #' @export #' #' @examples @@ -231,7 +219,7 @@ aet01_2 <- function(adam_db, tbl <- set_decoration(tbl, deco) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl @@ -247,7 +235,6 @@ aet01_2 <- function(adam_db, #' @param medconcept_var (`character`) the medical concept variables to be summarized. #' @param lbl_medconcept_var (`character`) the label of the medical concept variables to be summarized. #' -#' @return #' @export #' #' @examples @@ -280,8 +267,7 @@ aet01_2_lyt <- function(armvar = .study$actualarm, names(lbl_safety_var) <- safety_var names(lbl_medconcept_var) <- medconcept_var - lyt_adae <- - basic_table_deco(deco) %>% + lyt_adae <- basic_table_deco(deco) %>% split_cols_by(var = armvar) %>% add_colcounts() %>% ifneeded_add_overall_col(lbl_overall) %>% @@ -312,8 +298,7 @@ aet01_2_lyt <- function(armvar = .study$actualarm, .indent_mods = 0L ) - lyt_adsl <- - basic_table_deco(deco) %>% + lyt_adsl <- basic_table_deco(deco) %>% split_cols_by(var = armvar) %>% add_colcounts() %>% ifneeded_add_overall_col(lbl_overall) %>% diff --git a/R/aet02.R b/R/aet02.R index 2d260bccb9..25ed0202ef 100644 --- a/R/aet02.R +++ b/R/aet02.R @@ -13,13 +13,11 @@ #' * Sort Dictionary-Derived Code (`AEDECOD`) by highest overall frequencies. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(rtables) #' #' db <- syn_test_data() %>% #' preprocess_data("aet02_1") @@ -39,7 +37,7 @@ #' #' db_m <- db %>% #' dm_zoom_to(adae) %>% -#' mutate(AEBODSYS = with_label(AEBODSYS, "Medra System Organ Class")) %>% +#' mutate(AEBODSYS = formatters::with_label(AEBODSYS, "Medra System Organ Class")) %>% #' dm_update_zoomed() #' #' aet02_1(db_m) %>% head() @@ -65,7 +63,7 @@ aet02_1 <- function(adam_db, tbl <- build_table(lyt, dbsel$adae, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% @@ -167,14 +165,11 @@ aet02_1_lyt <- function(armvar = .study$actualarm, #' @export #' #' @examples -#' #' library(dm) -#' library(rtables) #' #' db <- syn_test_data() %>% #' preprocess_data("aet02_2") #' -#' #' aet02_2(db) %>% head(15) #' #' # Additional Examples @@ -182,7 +177,7 @@ aet02_1_lyt <- function(armvar = .study$actualarm, #' #' db_m <- db %>% #' dm_zoom_to(adae) %>% -#' mutate(AEBODSYS = with_label(AEBODSYS, "MedDRA System Organ Class")) %>% +#' mutate(AEBODSYS = formatters::with_label(AEBODSYS, "MedDRA System Organ Class")) %>% #' dm_update_zoomed() #' #' aet02_2(db_m) %>% head() @@ -210,7 +205,7 @@ aet02_2 <- function(adam_db, tbl <- build_table(lyt, adae, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% @@ -364,7 +359,7 @@ aet02_3 <- function(adam_db, tbl <- build_table(lyt, adam_db$adae, alt_counts_df = adam_db$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% diff --git a/R/aet03.R b/R/aet03.R index 1d7e90d6e5..06f1110918 100644 --- a/R/aet03.R +++ b/R/aet03.R @@ -14,14 +14,11 @@ #' * Sort by Body System or Organ Class (`SOC`) and Dictionary-Derived Term (`PT`). #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples -#' #' library(dm) -#' library(rtables) #' #' db <- syn_test_data() %>% #' preprocess_data("aet03_1") diff --git a/R/aet04.R b/R/aet04.R index ad130afcda..3f9e2b7f0c 100644 --- a/R/aet04.R +++ b/R/aet04.R @@ -14,13 +14,11 @@ #' Grade is sorted by severity. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(rtables) #' #' db <- syn_test_data() %>% #' preprocess_data("aet03_1") diff --git a/R/assertions.R b/R/assertions.R index bccce92461..0585d45781 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -17,7 +17,6 @@ #' my_colnames <- NULL #' assert_colnames(mtcars, my_colnames, null_ok = FALSE) #' } -#' assert_colnames <- function(df, x, null_ok = TRUE) { if (!null_ok && is.null(x)) { stop( diff --git a/R/cmt01a.R b/R/cmt01a.R index 6f5c05c49e..7581f47ac4 100644 --- a/R/cmt01a.R +++ b/R/cmt01a.R @@ -21,13 +21,11 @@ #' the specific medication. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to(adcm) %>% @@ -64,7 +62,7 @@ cmt01a_1 <- function(adam_db, tbl <- build_table(lyt, dbsel$adcm, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% @@ -168,13 +166,11 @@ cmt01a_1_lyt <- function(armvar = .study$planarm, #' the specific medication. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to(adcm) %>% @@ -212,7 +208,7 @@ cmt01a_2 <- function(adam_db, tbl <- build_table(lyt, dbsel$adcm, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% @@ -254,13 +250,11 @@ cmt01a_2 <- function(adam_db, #' the specific medication. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to(adcm) %>% @@ -297,7 +291,7 @@ cmt01a_3 <- function(adam_db, tbl <- build_table(lyt, dbsel$adcm, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% diff --git a/R/cmt02_pt.R b/R/cmt02_pt.R index 5e753faf5b..85d130fd83 100644 --- a/R/cmt02_pt.R +++ b/R/cmt02_pt.R @@ -10,12 +10,10 @@ #' * Order by decreasing total number of patients with the specific medication. #' * Does not include a total column by default. #' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to(adcm) %>% @@ -44,7 +42,7 @@ cmt02_pt_1 <- function(adam_db, tbl <- build_table(lyt, dbsel$adcm, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl %>% diff --git a/R/dm_explicit_na.R b/R/dm_explicit_na.R index 98a65a04be..25d218552a 100644 --- a/R/dm_explicit_na.R +++ b/R/dm_explicit_na.R @@ -14,7 +14,6 @@ #' @importFrom checkmate assert_class assert_character assert_logical #' @importFrom dm dm_zoom_to dm_update_zoomed #' @importFrom dplyr mutate across -#' @importFrom magrittr %>% #' @importFrom tern explicit_na sas_na #' #' @return `dm` object with explicit missing levels @@ -89,7 +88,7 @@ dm_explicit_na <- function(data, if (length(names_fact_col) > 0L) { data <- data %>% dm_zoom_to(!!tab_sym) %>% - mutate(across(names_fact_col, function(x) explicit_na(sas_na(x), label = na_level))) %>% + mutate(across(names_fact_col, function(x) tern::explicit_na(sas_na(x), label = na_level))) %>% dm_update_zoomed() } } @@ -106,16 +105,13 @@ dm_explicit_na <- function(data, #' #' @importFrom checkmate assert_true #' @importFrom tern explicit_na sas_na -#' -#' @return -#' h_as_factor <- function(x, na_label) { assert_true(is.character(x) || is.logical(x)) init_lab <- attr(x, "label") x_chr <- as.character(x) - res <- explicit_na(sas_na(x_chr), label = na_label) + res <- tern::explicit_na(sas_na(x_chr), label = na_label) lvl_x <- setdiff(sort(unique(res)), na_label) diff --git a/R/dmt01.R b/R/dmt01.R index bc6c80c0f2..7749e57ebc 100644 --- a/R/dmt01.R +++ b/R/dmt01.R @@ -16,14 +16,10 @@ #' * Split columns by arm (planned or actual / code or description) #' * Include a total column by default #' -#' @importFrom magrittr %>% -#' #' @export #' #' @examples -#' #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' preprocess_data("dmt01_1") diff --git a/R/dst01.R b/R/dst01.R index 3359cab04c..5a733d5ca2 100644 --- a/R/dst01.R +++ b/R/dst01.R @@ -39,12 +39,10 @@ check_dst01_1_args <- function(reason, status, status_treatment) { #' * Sort withdrawal reasons by alphabetic order. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples -#' #' library(dm) #' #' db <- syn_test_data() %>% @@ -480,7 +478,7 @@ dst01_3 <- function(adam_db, col_info(tbl) <- col_info(tbl2) - if (prune_0) tbl <- tbl %>% prune_table() + if (prune_0) tbl <- prune_table(tbl) tbl <- rbind(tbl2, tbl) diff --git a/R/dtht01.R b/R/dtht01.R index 428b6e323c..4be9bd67a3 100644 --- a/R/dtht01.R +++ b/R/dtht01.R @@ -14,20 +14,17 @@ #' * Remove zero-count rows unless overridden with `prune_0 = FALSE`. #' * Does not include a total column by default. #' -#' @importFrom magrittr %>% #' @importFrom checkmate assert_factor assert_logical #' #' @export #' #' @examples -#' library(tern) #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to(adsl) %>% -#' mutate(DTHCAT = explicit_na(DTHCAT)) %>% -#' mutate(LDDTHGR1 = explicit_na(LDDTHGR1)) %>% +#' mutate(DTHCAT = tern::explicit_na(DTHCAT)) %>% +#' mutate(LDDTHGR1 = tern::explicit_na(LDDTHGR1)) %>% #' dm_update_zoomed() %>% #' preprocess_data("dtht01_1") #' @@ -82,7 +79,7 @@ dtht01_1 <- function(adam_db, } if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl diff --git a/R/egt01.R b/R/egt01.R index 224d383535..a3e1d1de80 100644 --- a/R/egt01.R +++ b/R/egt01.R @@ -60,7 +60,7 @@ egt01_1 <- function(adam_db, df = adam_db$adeg ) - if (prune_0) tbl <- tbl %>% prune_table() + if (prune_0) tbl <- prune_table(tbl) tbl } @@ -78,7 +78,6 @@ egt01_1 <- function(adam_db, #' @param lbl_avisit (`character`) label of the `visitvar` variable. #' @param lbl_param (`character`) label of the `PARAM` variable. #' -#' @return #' @export egt01_1_lyt <- function(armvar = .study$actualarm, summaryvars = .study$evo_vars, diff --git a/R/egt02.R b/R/egt02.R index 23c95563d6..74379c21f8 100644 --- a/R/egt02.R +++ b/R/egt02.R @@ -16,12 +16,10 @@ #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to("adeg") %>% @@ -66,7 +64,6 @@ egt02_1 <- function(adam_db, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples @@ -115,12 +112,10 @@ egt02_1_lyt <- function(armvar = .study$actualarm, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to("adeg") %>% @@ -165,7 +160,6 @@ egt02_2 <- function(adam_db, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples diff --git a/R/ext01.R b/R/ext01.R index d44981ee88..8fbf28c41d 100644 --- a/R/ext01.R +++ b/R/ext01.R @@ -20,7 +20,6 @@ #' @export #' #' @examples -#' #' library(dm) #' #' db <- syn_test_data() %>% @@ -49,7 +48,7 @@ ext01_1 <- function(adam_db, tbl <- build_table(lyt, adam_db$adex, adam_db$adsl) - if (prune_0) tbl <- tbl %>% prune_table() + if (prune_0) tbl <- prune_table(tbl) tbl } @@ -109,7 +108,6 @@ ext01_1_lyt <- function(armvar = .study$actualarm, #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' preprocess_data("ext01_2") @@ -139,7 +137,7 @@ ext01_2 <- function(adam_db, tbl <- build_table(lyt, adam_db$adex, adam_db$adsl) - if (prune_0) tbl <- tbl %>% prune_table() + if (prune_0) tbl <- prune_table(tbl) tbl } diff --git a/R/mht01.R b/R/mht01.R index d3348b392f..1039e4d7b3 100644 --- a/R/mht01.R +++ b/R/mht01.R @@ -15,13 +15,11 @@ #' patients with the specific condition. #' #' @importFrom dplyr filter -#' @importFrom magrittr %>% #' #' @export #' #' @examples #' library(dm) -#' library(rtables) #' #' db <- syn_test_data() %>% #' preprocess_data("mht01_1") @@ -51,7 +49,7 @@ mht01_1 <- function(adam_db, tbl <- build_table(lyt, dbsel$admh, alt_counts_df = dbsel$adsl) if (prune_0) { - tbl <- tbl %>% prune_table() + tbl <- prune_table(tbl) } tbl_sorted <- tbl %>% diff --git a/R/package.R b/R/package.R index a25d3b15b8..25f4f8e39e 100644 --- a/R/package.R +++ b/R/package.R @@ -1,12 +1,13 @@ #' Chevron Package #' -#' @import tern +#' @import dm +#' @import dplyr #' @import rtables +#' @import tern #' @importFrom assertthat assert_that on_failure<- -#' @importFrom tibble tribble -#' @import dplyr -#' @import dm +#' @importFrom magrittr %>% #' @importFrom methods is #' @importFrom stats setNames +#' @importFrom tibble tribble "_PACKAGE" diff --git a/R/sample_study_object.R b/R/sample_study_object.R index 6b4ba63f92..7be97a040f 100644 --- a/R/sample_study_object.R +++ b/R/sample_study_object.R @@ -11,7 +11,7 @@ sample_study_object <- function() { # list functions - ls_exported <- as.vector(lsf.str("package:chevron")) + ls_exported <- as.vector(utils::lsf.str("package:chevron")) # Get the arguments of each exported function. ls_args <- lapply(ls_exported, formals) diff --git a/R/standard_data_preprocessing.R b/R/standard_data_preprocessing.R index 09c8dedc23..b857758f46 100644 --- a/R/standard_data_preprocessing.R +++ b/R/standard_data_preprocessing.R @@ -1,6 +1,12 @@ - - -std_preprocessing_map <- tibble::tribble( +#' Standard Preprocessing Map +#' +#' The preprocessing map contains information how the ADaM data needs to be preprocessed for each function. +#' +#' @export +#' +#' @examples +#' std_pmap +std_pmap <- tibble::tribble( ~tlgfname, ~filter_fname, ~mutate_fname, ~req_data, "aet01_1", "filter_adae_anl01fl", "mutate_for_aet01", c("adsl", "adae"), "aet01_2", "filter_adae_anl01fl", "mutate_for_aet01", c("adsl", "adae"), @@ -30,19 +36,6 @@ std_preprocessing_map <- tibble::tribble( "vst02_2", "filter_vst02", "mutate_vst02", c("adsl", "advs") ) -#' Standard Preprocessing Map -#' -#' The preprocessing map contains information how the ADaM data needs to be preprocessed for each function. -#' -#' -#' @export -#' -#' @examples -#' std_pmap() -std_pmap <- function() { - std_preprocessing_map -} - #' Row in Preprocessing Map #' #' @param tlgfname (`character`) name of a function which creates a table, listing or graph @@ -54,7 +47,6 @@ std_pmap <- function() { #' @export #' #' @examples -#' #' pmap_row("tabc", NA, "identity", c("adsl", "adae")) pmap_row <- function(tlgfname, filter_fname = NA, mutate_fname = NA, req_data) { fnames <- list(tlgfname, filter_fname, mutate_fname) @@ -73,29 +65,14 @@ pmap_row <- function(tlgfname, filter_fname = NA, mutate_fname = NA, req_data) { ) } - -#' Append A Preprocessing Map Entry -#' -#' -#' @param x (`data.frame`) in the structure returned from `std_pmap` or `pmap_entry` -#' @param y (`data.frame`) in the structure returned from `std_pmap` or `pmap_entry` -#' -#' @export -#' -append_to_pmap <- function(x, y) { - rbind(x, y) -} - #' Remove Row For a tlgfunction from a pre-processing map #' #' @inheritParams gen_args #' -#' #' @export #' #' @examples -#' -#' remove_tlg_pmap(std_pmap(), "aet02_1") +#' remove_tlg_pmap(std_pmap, "aet02_1") remove_tlg_pmap <- function(pmap, tlgfname) { assert_that(tlgfname %in% pmap$tlgfname) @@ -107,9 +84,9 @@ lookup_fun <- function(fname, what, pmap) { assert_that(fname %in% pmap$tlgfname) fstr <- pmap %>% - filter(tlgfname == fname) %>% - slice(1) %>% - pull(what) + dplyr::filter(tlgfname == fname) %>% + dplyr::slice(1) %>% + dplyr::pull(what) if (is.na(fstr)) { identity @@ -130,9 +107,9 @@ get_req_data <- function(id, pmap) { assert_that(id %in% pmap$tlgfname) fstr <- pmap %>% - filter(tlgfname == id) %>% - slice(1) %>% - pull(req_data) + dplyr::filter(tlgfname == id) %>% + dplyr::slice(1) %>% + dplyr::pull(req_data) fstr[[1]] } @@ -149,7 +126,7 @@ get_req_data <- function(id, pmap) { #' #' db %>% #' preprocess_data("aet02_2") -preprocess_data <- function(adam_db, tlgfname, pmap = std_pmap(), .study) { +preprocess_data <- function(adam_db, tlgfname, pmap = std_pmap, .study) { assert_that( all(get_req_data(tlgfname, pmap) %in% names(adam_db)), msg = paste( @@ -186,7 +163,7 @@ preprocess_data <- function(adam_db, tlgfname, pmap = std_pmap(), .study) { #' #' @examples #' std_filter_fun("aet02_1") -std_filter_fun <- function(tlgfname, pmap = std_pmap()) { +std_filter_fun <- function(tlgfname, pmap = std_pmap) { lookup_fun(tlgfname, "filter_fname", pmap) } @@ -198,7 +175,7 @@ std_filter_fun <- function(tlgfname, pmap = std_pmap()) { #' #' @examples #' std_mutate_fun("aet02_1") -std_mutate_fun <- function(tlgfname, pmap = std_pmap()) { +std_mutate_fun <- function(tlgfname, pmap = std_pmap) { lookup_fun(tlgfname, "mutate_fname", pmap) } @@ -207,8 +184,6 @@ std_mutate_fun <- function(tlgfname, pmap = std_pmap()) { #' @inheritParams gen_args #' #' @importFrom dplyr filter -#' -#' filter_adae_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -221,7 +196,6 @@ filter_adae_anl01fl <- function(adam_db) { #' Filter `adlb` for `ANL01FL` #' #' @inheritParams gen_args -#' filter_adlb_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -234,7 +208,6 @@ filter_adlb_anl01fl <- function(adam_db) { #' Filter `adeg` for `ANL01FL` #' #' @inheritParams gen_args -#' filter_adeg_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -247,7 +220,6 @@ filter_adeg_anl01fl <- function(adam_db) { #' Filter `advs` for `ANL01FL` #' #' @inheritParams gen_args -#' filter_advs_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -260,7 +232,6 @@ filter_advs_anl01fl <- function(adam_db) { #' Filter `admh` for `ANL01FL` #' #' @inheritParams gen_args -#' filter_admh_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -273,7 +244,6 @@ filter_admh_anl01fl <- function(adam_db) { #' Filter `adex` for `PARCAT1` #' #' @inheritParams gen_args -#' filter_adex_drug <- function(adam_db) { assert_that(is(adam_db, "dm")) @@ -288,7 +258,6 @@ filter_adex_drug <- function(adam_db) { #' @details filter with `ANL01FL` (instead of `SAFFL ` which is external to `chevron`). #' #' @inheritParams gen_args -#' filter_adcm_anl01fl <- function(adam_db) { assert_that(is(adam_db, "dm")) adam_db %>% @@ -300,7 +269,6 @@ filter_adcm_anl01fl <- function(adam_db) { #' Filter post-baseline values in `advs` #' #' @inheritParams gen_args -#' filter_vst02 <- function(adam_db) { assert_that(is(adam_db, "dm")) adam_db %>% @@ -313,7 +281,6 @@ filter_vst02 <- function(adam_db) { #' Filter post-baseline values in `adeg` #' #' @inheritParams gen_args -#' filter_egt02 <- function(adam_db) { assert_that(is(adam_db, "dm")) adam_db %>% @@ -324,8 +291,8 @@ filter_egt02 <- function(adam_db) { } #' Creating Necessary Columns for `aet01` -#' @inheritParams gen_args #' +#' @inheritParams gen_args mutate_for_aet01 <- function(adam_db) { db <- adam_db %>% dm_zoom_to(adae) %>% @@ -377,7 +344,6 @@ mutate_for_aet01 <- function(adam_db) { #' #' @inheritParams gen_args #' @param reason (`character`) the variable name for variable with the reason for discontinuation. -#' mutate_adsl_gp <- function(adam_db, reason = .study$disc_reason_var, .study = list(disc_reason_var = "DCSREAS")) { @@ -399,7 +365,6 @@ mutate_adsl_gp <- function(adam_db, #' Coerce `CMSEQ` to factor in `adcm` #' #' @inheritParams gen_args -#' mutate_cmt01a <- function(adam_db) { adam_db %>% dm_zoom_to(adcm) %>% @@ -415,7 +380,6 @@ mutate_cmt01a <- function(adam_db) { #' @param paramcd_order (`vector of character`) providing the `PARAMCD` values in the desired order. #' #' @return a `dm` object. -#' reorder_adex_params <- function(adam_db, paramcd_order = .study$paramcd_order, .study = list(paramcd_order = c("TNDOSE", "DOSE", "NDOSE", "TDOSE"))) { @@ -441,7 +405,6 @@ reorder_adex_params <- function(adam_db, #' #' @param show_bins (`vector of character`) providing the name of the parameters whose categorical summary should be #' presented. To analyze all, provide `show_bins = "ALL"` (Default), to analyze none, provide `show_bins = ""`. -#' remove_adex_aval <- function(adam_db, show_stats = .study$show_cont_stats, show_bins = .study$show_cat_stats, @@ -474,7 +437,6 @@ remove_adex_aval <- function(adam_db, #' @inheritParams gen_args #' #' @importFrom forcats fct_relevel -#' reorder_dtht01 <- function(adam_db) { death_fact <- levels(adam_db$adsl$DTHCAT) death_fact <- setdiff(death_fact, "OTHER") @@ -488,12 +450,9 @@ reorder_dtht01 <- function(adam_db) { db } -#' Mutate Function for `CMT02_PT_1` +#' Mutate function for `CMT02_PT_1` #' #' @inheritParams gen_args -#' -#' @return -#' mutate_cmt02_pt_1 <- function(adam_db) { db <- adam_db %>% dm_zoom_to(adcm) %>% @@ -503,12 +462,9 @@ mutate_cmt02_pt_1 <- function(adam_db) { db } -#' Mutate Function for `DMT01_1` +#' Mutate function for `DMT01_1` #' #' @inheritParams gen_args -#' -#' @return -#' mutate_dmt01 <- function(adam_db) { adsl_lbs <- formatters::var_labels(adam_db$adsl) db <- adam_db %>% @@ -525,7 +481,6 @@ mutate_dmt01 <- function(adam_db) { #' Categorize `advs` values #' #' @inheritParams gen_args -#' mutate_vst02 <- function(adam_db) { db <- adam_db %>% dm_zoom_to(advs) %>% diff --git a/R/utils.R b/R/utils.R index b763811d41..69125a29f7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,7 +5,7 @@ globalVariables(c( "req_data", "tlgfname" )) -#' Retrieve Variables for Certain variables +#' Retrieve variables for certain variables #' #' @param df data frame #' @param vars variable names in data frame `df` @@ -18,7 +18,7 @@ var_labels_for <- function(df, vars) { } -#' Standard Documentation Lookup +#' Standard documentation lookup #' #' @param id standard id of output #' @param ... not used at the moment @@ -92,11 +92,9 @@ bol_YN <- function(x) { # nolint #' ) #' #' library(scda) -#' library(dplyr) #' sd <- synthetic_cdisc_data("rcd_2021_03_22") #' adsl <- sd$adsl -#' adex <- sd$adex %>% -#' mutate(ANL01FL = "Y") +#' adex <- dplyr::mutate(sd$adex, ANL01FL = "Y") #' #' adex_gp <- cut_by_group(adex, "AVAL", "PARAM", group, "AVAL_gp") #' @@ -134,7 +132,6 @@ cut_by_group <- function(df, #' @export #' #' @examples -#' #' df <- data.frame(PARAMCD = factor(c("A", "B", "C")), PARAM = factor(paste("letter", LETTERS[1:3]))) #' #' str(reorder_levels_params(df, paramcd_levels = c("B", "A", "C"))) @@ -181,7 +178,6 @@ reorder_levels_params <- function(df, paramcd_levels) { #' @export #' #' @examples -#' #' library(scda) #' adsub <- synthetic_cdisc_data("rcd_2021_03_22")$adsub #' pivot_wider_labels(adsub, "PARAMCD", "PARAM", "AVAL", c("USUBJID", "SUBJID")) @@ -257,7 +253,6 @@ ifneeded_add_overall_col <- function(lyt, lbl_overall) { #' #' get_db_data(db, "airports") #' } -#' get_db_data <- function(db, ...) { # TODO: revisit datasets <- c(...) @@ -368,8 +363,11 @@ syn_test_data <- function() { #' @param deco (`list`) typically generated with `std_deco()`. #' #' @return `rtables` with set title, subtitle and footnotes. If one of this attribute is NULL, the slot is empty. -#' set_decoration <- function(x, deco) { + checkmate::assert_class(x, "TableTree") + checkmate::assert_list(deco, types = "character", max.len = 3, names = "unique") + checkmate::assert_subset(names(deco), c("title", "subtitles", "main_footer")) + x@main_title <- deco$title x@subtitles <- deco$subtitles x@main_footer <- deco$main_footer diff --git a/R/vst01.R b/R/vst01.R index e23c8ce8d3..1f499b92ec 100644 --- a/R/vst01.R +++ b/R/vst01.R @@ -80,7 +80,6 @@ vst01_1 <- function(adam_db, #' @param lbl_avisit (`character`) label of the `visitvar` variable. #' @param lbl_param (`character`) label of the `PARAM` variable. #' -#' @return #' @export vst01_1_lyt <- function(armvar = .study$actualarm, summaryvars = .study$evo_vars, diff --git a/R/vst02.R b/R/vst02.R index 83062705ac..6d3e59a834 100644 --- a/R/vst02.R +++ b/R/vst02.R @@ -16,12 +16,10 @@ #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to("advs") %>% @@ -66,7 +64,6 @@ vst02_1 <- function(adam_db, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples @@ -115,12 +112,10 @@ vst02_1_lyt <- function(armvar = .study$actualarm, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples #' library(dm) -#' library(dplyr) #' #' db <- syn_test_data() %>% #' dm_zoom_to("advs") %>% @@ -164,7 +159,6 @@ vst02_2 <- function(adam_db, #' @param lbl_vs_assessment (`character`) the label of the assessment variable. #' @param lbl_vs_abnormality (`character`) the label of the abnormality variable. #' -#' @return #' @export #' #' @examples diff --git a/man/aet01_1.Rd b/man/aet01_1.Rd index db370757db..90efb96b22 100644 --- a/man/aet01_1.Rd +++ b/man/aet01_1.Rd @@ -45,11 +45,6 @@ aet01_1_lyt( \item{lbl_safety_var}{(\code{character}) the labels of the safety variables to be summarized.} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Overview of death and summary of adverse events. @@ -66,7 +61,6 @@ Overview of death and summary of adverse events. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% preprocess_data("aet01_1") diff --git a/man/aet01_2.Rd b/man/aet01_2.Rd index 8a78195312..06091629b4 100644 --- a/man/aet01_2.Rd +++ b/man/aet01_2.Rd @@ -55,11 +55,6 @@ aet01_2_lyt( \item{lbl_medconcept_var}{(\code{character}) the label of the medical concept variables to be summarized.} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Overview of death and summary of adverse events with medical concepts. diff --git a/man/aet02_1.Rd b/man/aet02_1.Rd index 8f047a54eb..cc14799742 100644 --- a/man/aet02_1.Rd +++ b/man/aet02_1.Rd @@ -60,7 +60,6 @@ events categorized by Body System and Dictionary-Derived Term. \examples{ library(dm) -library(rtables) db <- syn_test_data() \%>\% preprocess_data("aet02_1") @@ -80,7 +79,7 @@ aet02_1(db, lbl_overall = "All Patients") \%>\% head() db_m <- db \%>\% dm_zoom_to(adae) \%>\% - mutate(AEBODSYS = with_label(AEBODSYS, "Medra System Organ Class")) \%>\% + mutate(AEBODSYS = formatters::with_label(AEBODSYS, "Medra System Organ Class")) \%>\% dm_update_zoomed() aet02_1(db_m) \%>\% head() diff --git a/man/aet02_2.Rd b/man/aet02_2.Rd index e740c9638f..66f7a712ca 100644 --- a/man/aet02_2.Rd +++ b/man/aet02_2.Rd @@ -63,14 +63,11 @@ frequencies. }} \examples{ - library(dm) -library(rtables) db <- syn_test_data() \%>\% preprocess_data("aet02_2") - aet02_2(db) \%>\% head(15) # Additional Examples @@ -78,7 +75,7 @@ aet02_2(db, lbl_overall = "All Patients") \%>\% head() db_m <- db \%>\% dm_zoom_to(adae) \%>\% - mutate(AEBODSYS = with_label(AEBODSYS, "MedDRA System Organ Class")) \%>\% + mutate(AEBODSYS = formatters::with_label(AEBODSYS, "MedDRA System Organ Class")) \%>\% dm_update_zoomed() aet02_2(db_m) \%>\% head() diff --git a/man/aet03_1.Rd b/man/aet03_1.Rd index 91457cfd80..1ca32f99c0 100644 --- a/man/aet03_1.Rd +++ b/man/aet03_1.Rd @@ -63,9 +63,7 @@ An adverse events table categorized by System Organ Class, Dictionary-Derived Te }} \examples{ - library(dm) -library(rtables) db <- syn_test_data() \%>\% preprocess_data("aet03_1") diff --git a/man/aet04_1.Rd b/man/aet04_1.Rd index ec86b646ff..16ced6925a 100644 --- a/man/aet04_1.Rd +++ b/man/aet04_1.Rd @@ -64,7 +64,6 @@ Grade is sorted by severity. \examples{ library(dm) -library(rtables) db <- syn_test_data() \%>\% preprocess_data("aet03_1") diff --git a/man/append_to_pmap.Rd b/man/append_to_pmap.Rd deleted file mode 100644 index 5f09559163..0000000000 --- a/man/append_to_pmap.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/standard_data_preprocessing.R -\name{append_to_pmap} -\alias{append_to_pmap} -\title{Append A Preprocessing Map Entry} -\usage{ -append_to_pmap(x, y) -} -\arguments{ -\item{x}{(\code{data.frame}) in the structure returned from \code{std_pmap} or \code{pmap_entry}} - -\item{y}{(\code{data.frame}) in the structure returned from \code{std_pmap} or \code{pmap_entry}} -} -\description{ -Append A Preprocessing Map Entry -} diff --git a/man/assert_colnames.Rd b/man/assert_colnames.Rd index 4e6eee96e3..267da2e1dd 100644 --- a/man/assert_colnames.Rd +++ b/man/assert_colnames.Rd @@ -23,5 +23,4 @@ assert_colnames(mtcars, c("speed", "seats"), null_ok = TRUE) my_colnames <- NULL assert_colnames(mtcars, my_colnames, null_ok = FALSE) } - } diff --git a/man/cmt01a_1.Rd b/man/cmt01a_1.Rd index ffe2a16ed0..ef3c481654 100644 --- a/man/cmt01a_1.Rd +++ b/man/cmt01a_1.Rd @@ -72,7 +72,6 @@ the specific medication. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to(adcm) \%>\% diff --git a/man/cmt01a_2.Rd b/man/cmt01a_2.Rd index ad31dbf96c..9c246d4b0e 100644 --- a/man/cmt01a_2.Rd +++ b/man/cmt01a_2.Rd @@ -56,7 +56,6 @@ the specific medication. } \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to(adcm) \%>\% diff --git a/man/cmt01a_3.Rd b/man/cmt01a_3.Rd index 8f4fa916ab..c8f18a60d1 100644 --- a/man/cmt01a_3.Rd +++ b/man/cmt01a_3.Rd @@ -74,7 +74,6 @@ the specific medication. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to(adcm) \%>\% diff --git a/man/cmt02_pt_1.Rd b/man/cmt02_pt_1.Rd index 4848e07a15..e1b4f130dd 100644 --- a/man/cmt02_pt_1.Rd +++ b/man/cmt02_pt_1.Rd @@ -33,9 +33,6 @@ cmt02_pt_1_lyt( \item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - } \description{ A concomitant medication table with the number of subjects and the total number of treatments by medication name @@ -55,7 +52,6 @@ sorted by frequencies. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to(adcm) \%>\% diff --git a/man/cut_by_group.Rd b/man/cut_by_group.Rd index 9ae8bbf25a..9eef6b4441 100644 --- a/man/cut_by_group.Rd +++ b/man/cut_by_group.Rd @@ -40,11 +40,9 @@ group <- list( ) library(scda) -library(dplyr) sd <- synthetic_cdisc_data("rcd_2021_03_22") adsl <- sd$adsl -adex <- sd$adex \%>\% - mutate(ANL01FL = "Y") +adex <- dplyr::mutate(sd$adex, ANL01FL = "Y") adex_gp <- cut_by_group(adex, "AVAL", "PARAM", group, "AVAL_gp") diff --git a/man/dmt01_1.Rd b/man/dmt01_1.Rd index 91a8d68323..65c68985a8 100644 --- a/man/dmt01_1.Rd +++ b/man/dmt01_1.Rd @@ -63,9 +63,7 @@ For each variable, summary statistics are by default based on the number of pati }} \examples{ - library(dm) -library(dplyr) db <- syn_test_data() \%>\% preprocess_data("dmt01_1") diff --git a/man/dst01_1.Rd b/man/dst01_1.Rd index 036672b627..0ede9b4754 100644 --- a/man/dst01_1.Rd +++ b/man/dst01_1.Rd @@ -86,7 +86,6 @@ which allows the tables to be constructed and pruned separately before binding. }} \examples{ - library(dm) db <- syn_test_data() \%>\% diff --git a/man/dtht01_1.Rd b/man/dtht01_1.Rd index 00fe731a3c..d85c03dd2d 100644 --- a/man/dtht01_1.Rd +++ b/man/dtht01_1.Rd @@ -68,14 +68,12 @@ reporting of death. }} \examples{ -library(tern) library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to(adsl) \%>\% - mutate(DTHCAT = explicit_na(DTHCAT)) \%>\% - mutate(LDDTHGR1 = explicit_na(LDDTHGR1)) \%>\% + mutate(DTHCAT = tern::explicit_na(DTHCAT)) \%>\% + mutate(LDDTHGR1 = tern::explicit_na(LDDTHGR1)) \%>\% dm_update_zoomed() \%>\% preprocess_data("dtht01_1") diff --git a/man/egt01_1.Rd b/man/egt01_1.Rd index 354f4a9438..b0003cbefa 100644 --- a/man/egt01_1.Rd +++ b/man/egt01_1.Rd @@ -49,9 +49,6 @@ to be displayed.} \item{lbl_avisit}{(\code{character}) label of the \code{visitvar} variable.} \item{lbl_param}{(\code{character}) label of the \code{PARAM} variable.} -} -\value{ - } \description{ The \code{EGT01} table 1 summarizes several electrocardiogram parameters and their evolution throughout the study. diff --git a/man/egt02_1.Rd b/man/egt02_1.Rd index bcf6f3b177..b935fcfa57 100644 --- a/man/egt02_1.Rd +++ b/man/egt02_1.Rd @@ -41,11 +41,6 @@ egt02_1_lyt( \item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Assessments Outside Normal Limits Regardless of Abnormality at Baseline Table. @@ -65,7 +60,6 @@ Assessments Outside Normal Limits Regardless of Abnormality at Baseline Table. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to("adeg") \%>\% diff --git a/man/egt02_2.Rd b/man/egt02_2.Rd index c3234f6087..841ee55e32 100644 --- a/man/egt02_2.Rd +++ b/man/egt02_2.Rd @@ -41,11 +41,6 @@ egt02_2_lyt( \item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Assessments Outside Normal Limits Among Subject Without Abnormality at Baseline. @@ -65,7 +60,6 @@ Assessments Outside Normal Limits Among Subject Without Abnormality at Baseline. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to("adeg") \%>\% diff --git a/man/ext01_1.Rd b/man/ext01_1.Rd index 49379b67db..71125ad553 100644 --- a/man/ext01_1.Rd +++ b/man/ext01_1.Rd @@ -64,7 +64,6 @@ patients in the corresponding analysis population given by \code{N}. }} \examples{ - library(dm) db <- syn_test_data() \%>\% diff --git a/man/ext01_2.Rd b/man/ext01_2.Rd index 9ffd129458..1f5f97ce7e 100644 --- a/man/ext01_2.Rd +++ b/man/ext01_2.Rd @@ -64,7 +64,6 @@ patients in the corresponding analysis population given by \code{N}. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% preprocess_data("ext01_2") diff --git a/man/get_db_data.Rd b/man/get_db_data.Rd index 16f0c4fee5..71002d1f88 100644 --- a/man/get_db_data.Rd +++ b/man/get_db_data.Rd @@ -28,5 +28,4 @@ db <- dm::dm_nycflights13() \%>\% get_db_data(db, "airports") } - } diff --git a/man/h_as_factor.Rd b/man/h_as_factor.Rd index dd4430db2a..2d857a11a5 100644 --- a/man/h_as_factor.Rd +++ b/man/h_as_factor.Rd @@ -10,9 +10,6 @@ h_as_factor(x, na_label) \item{x}{(\code{character} or \code{logical}) input to be turned into factor with explicit missing level.} \item{na_label}{(\code{character}) the label to encode missing levels.} -} -\value{ - } \description{ Helper Coercion Function to Factor with explicit missing levels diff --git a/man/mht01_1.Rd b/man/mht01_1.Rd index 8d9dada00f..d7fd043f63 100644 --- a/man/mht01_1.Rd +++ b/man/mht01_1.Rd @@ -62,7 +62,6 @@ patients with the specific condition. \examples{ library(dm) -library(rtables) db <- syn_test_data() \%>\% preprocess_data("mht01_1") diff --git a/man/mutate_cmt02_pt_1.Rd b/man/mutate_cmt02_pt_1.Rd index cfc9736543..ed6ad35082 100644 --- a/man/mutate_cmt02_pt_1.Rd +++ b/man/mutate_cmt02_pt_1.Rd @@ -2,16 +2,13 @@ % Please edit documentation in R/standard_data_preprocessing.R \name{mutate_cmt02_pt_1} \alias{mutate_cmt02_pt_1} -\title{Mutate Function for \code{CMT02_PT_1}} +\title{Mutate function for \code{CMT02_PT_1}} \usage{ mutate_cmt02_pt_1(adam_db) } \arguments{ \item{adam_db}{(\code{dm}) object containing the ADaM datasets} -} -\value{ - } \description{ -Mutate Function for \code{CMT02_PT_1} +Mutate function for \code{CMT02_PT_1} } diff --git a/man/mutate_dmt01.Rd b/man/mutate_dmt01.Rd index ab475ad873..714959b2f7 100644 --- a/man/mutate_dmt01.Rd +++ b/man/mutate_dmt01.Rd @@ -2,16 +2,13 @@ % Please edit documentation in R/standard_data_preprocessing.R \name{mutate_dmt01} \alias{mutate_dmt01} -\title{Mutate Function for \code{DMT01_1}} +\title{Mutate function for \code{DMT01_1}} \usage{ mutate_dmt01(adam_db) } \arguments{ \item{adam_db}{(\code{dm}) object containing the ADaM datasets} -} -\value{ - } \description{ -Mutate Function for \code{DMT01_1} +Mutate function for \code{DMT01_1} } diff --git a/man/pivot_wider_labels.Rd b/man/pivot_wider_labels.Rd index 1186bcaada..497de97e00 100644 --- a/man/pivot_wider_labels.Rd +++ b/man/pivot_wider_labels.Rd @@ -33,7 +33,6 @@ Typically a unique identifier for the pivoted observations, such as \code{USUBJI Pivot wider a data frame while preserving labels. } \examples{ - library(scda) adsub <- synthetic_cdisc_data("rcd_2021_03_22")$adsub pivot_wider_labels(adsub, "PARAMCD", "PARAM", "AVAL", c("USUBJID", "SUBJID")) diff --git a/man/pmap_row.Rd b/man/pmap_row.Rd index 7ec656b5f1..3707f263b3 100644 --- a/man/pmap_row.Rd +++ b/man/pmap_row.Rd @@ -20,6 +20,5 @@ output} Row in Preprocessing Map } \examples{ - pmap_row("tabc", NA, "identity", c("adsl", "adae")) } diff --git a/man/preprocess_data.Rd b/man/preprocess_data.Rd index f57fc718ba..ac6b339458 100644 --- a/man/preprocess_data.Rd +++ b/man/preprocess_data.Rd @@ -4,7 +4,7 @@ \alias{preprocess_data} \title{Preprocess ADaM Data for A TLG function} \usage{ -preprocess_data(adam_db, tlgfname, pmap = std_pmap(), .study) +preprocess_data(adam_db, tlgfname, pmap = std_pmap, .study) } \arguments{ \item{adam_db}{(\code{dm}) object containing the ADaM datasets} diff --git a/man/remove_tlg_pmap.Rd b/man/remove_tlg_pmap.Rd index 88e8714c24..dee7798360 100644 --- a/man/remove_tlg_pmap.Rd +++ b/man/remove_tlg_pmap.Rd @@ -15,6 +15,5 @@ remove_tlg_pmap(pmap, tlgfname) Remove Row For a tlgfunction from a pre-processing map } \examples{ - -remove_tlg_pmap(std_pmap(), "aet02_1") +remove_tlg_pmap(std_pmap, "aet02_1") } diff --git a/man/reorder_levels_params.Rd b/man/reorder_levels_params.Rd index 1ed4db11ee..1e592acb90 100644 --- a/man/reorder_levels_params.Rd +++ b/man/reorder_levels_params.Rd @@ -15,7 +15,6 @@ reorder_levels_params(df, paramcd_levels) Reorder PARAM and PARAMCD Levels Simultaneously } \examples{ - df <- data.frame(PARAMCD = factor(c("A", "B", "C")), PARAM = factor(paste("letter", LETTERS[1:3]))) str(reorder_levels_params(df, paramcd_levels = c("B", "A", "C"))) diff --git a/man/std_deco.Rd b/man/std_deco.Rd index c6aba920db..85cc3a1cf3 100644 --- a/man/std_deco.Rd +++ b/man/std_deco.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{std_deco} \alias{std_deco} -\title{Standard Documentation Lookup} +\title{Standard documentation lookup} \usage{ std_deco(id, ...) } @@ -12,5 +12,5 @@ std_deco(id, ...) \item{...}{not used at the moment} } \description{ -Standard Documentation Lookup +Standard documentation lookup } diff --git a/man/std_filter_fun.Rd b/man/std_filter_fun.Rd index 36715d30ad..de89657c3f 100644 --- a/man/std_filter_fun.Rd +++ b/man/std_filter_fun.Rd @@ -4,7 +4,7 @@ \alias{std_filter_fun} \title{Retrieve Standard Subsetting for Templates} \usage{ -std_filter_fun(tlgfname, pmap = std_pmap()) +std_filter_fun(tlgfname, pmap = std_pmap) } \arguments{ \item{tlgfname}{(\code{character}) function name of tlg-function} diff --git a/man/std_mutate_fun.Rd b/man/std_mutate_fun.Rd index 1fa8df2c78..da0608e8df 100644 --- a/man/std_mutate_fun.Rd +++ b/man/std_mutate_fun.Rd @@ -4,7 +4,7 @@ \alias{std_mutate_fun} \title{Retrieve Standard Mutation for Templates} \usage{ -std_mutate_fun(tlgfname, pmap = std_pmap()) +std_mutate_fun(tlgfname, pmap = std_pmap) } \arguments{ \item{tlgfname}{(\code{character}) function name of tlg-function} diff --git a/man/std_pmap.Rd b/man/std_pmap.Rd index 46e66534d0..6b677fb855 100644 --- a/man/std_pmap.Rd +++ b/man/std_pmap.Rd @@ -1,14 +1,19 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/standard_data_preprocessing.R +\docType{data} \name{std_pmap} \alias{std_pmap} \title{Standard Preprocessing Map} +\format{ +An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 26 rows and 4 columns. +} \usage{ -std_pmap() +std_pmap } \description{ The preprocessing map contains information how the ADaM data needs to be preprocessed for each function. } \examples{ -std_pmap() +std_pmap } +\keyword{datasets} diff --git a/man/var_labels_for.Rd b/man/var_labels_for.Rd index 041fcb6ffa..f015c52a01 100644 --- a/man/var_labels_for.Rd +++ b/man/var_labels_for.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/utils.R \name{var_labels_for} \alias{var_labels_for} -\title{Retrieve Variables for Certain variables} +\title{Retrieve variables for certain variables} \usage{ var_labels_for(df, vars) } @@ -12,5 +12,5 @@ var_labels_for(df, vars) \item{vars}{variable names in data frame \code{df}} } \description{ -Retrieve Variables for Certain variables +Retrieve variables for certain variables } diff --git a/man/vst01_1.Rd b/man/vst01_1.Rd index fb93014adb..5a5f3bc42f 100644 --- a/man/vst01_1.Rd +++ b/man/vst01_1.Rd @@ -49,9 +49,6 @@ to be displayed.} \item{lbl_avisit}{(\code{character}) label of the \code{visitvar} variable.} \item{lbl_param}{(\code{character}) label of the \code{PARAM} variable.} -} -\value{ - } \description{ The \code{VST01} table provides an overview of the Vital Sign values and its change from baseline of each respective arm diff --git a/man/vst02_1.Rd b/man/vst02_1.Rd index 94f4782dcf..289ed503f6 100644 --- a/man/vst02_1.Rd +++ b/man/vst02_1.Rd @@ -41,11 +41,6 @@ vst02_1_lyt( \item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Assessments Outside Normal Limits Regardless of Abnormality at Baseline Table. @@ -65,7 +60,6 @@ Assessments Outside Normal Limits Regardless of Abnormality at Baseline Table. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to("advs") \%>\% diff --git a/man/vst02_2.Rd b/man/vst02_2.Rd index 667241e381..d7e5924bfb 100644 --- a/man/vst02_2.Rd +++ b/man/vst02_2.Rd @@ -41,11 +41,6 @@ vst02_2_lyt( \item{deco}{(\code{character}) decoration with \code{title}, \code{subtitles} and \code{main_footer} content} \item{.study}{(\code{list}) with default values for the arguments of the function} -} -\value{ - - - } \description{ Assessments Outside Normal Limits Among Subject Without Abnormality at Baseline. @@ -66,7 +61,6 @@ Assessments Outside Normal Limits Among Subject Without Abnormality at Baseline. \examples{ library(dm) -library(dplyr) db <- syn_test_data() \%>\% dm_zoom_to("advs") \%>\% diff --git a/vignettes/introduction.Rmd b/vignettes/chevron.Rmd similarity index 93% rename from vignettes/introduction.Rmd rename to vignettes/chevron.Rmd index e3c93361e0..98bfd6f0e3 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/chevron.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteIndexEntry{Introduction to Chevron} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- @@ -19,7 +19,7 @@ knitr::opts_chunk$set( ``` -## Introduction +## Introduction The `chevron` R package provides functions to produce standard tables, listings and graphs (TLGs) used to analyze and report clinical trials data. We refer to these functions as *tlg-functions*. The *tlg-functions* in `chevron` use other @@ -29,7 +29,7 @@ packages to produce the final outputs, for example `rtables` and `tern` are used *tlg-functions* in `chevron` such as `dmt01_1`, `aet02_1`, `aet02_2` have the following properties: -1. they produce a narrow defined output (currently standards in Roche GDS). Note, that the naming convention +1. they produce a narrow defined output (currently standards in Roche GDS). Note, that the naming convention `_` indicates that a Roche GDS defined standard may have different implementations. Or, alternatively, a GDS template id can be regarded as a *guideline* and the function name in `chevron` as a *standard*. @@ -76,13 +76,12 @@ aet02_1(adam_db = db) # More on preprocess_data and processing map The `preprocess_data` function determines the the preprocessing using a *processing map* which is -referred to in `chevron` as `pmap`. +referred to in `chevron` as `pmap`. The standard preprocessing map that comes with the *tlg-functions* in `chevron` can be access via `std_pmap` ```{r} -std_pmap() %>% - head() +head(std_pmap) ``` For example, for `aet02_1`: @@ -92,8 +91,7 @@ For example, for `aet02_1`: 3. and the required data are in the `req_data` column accessible by ```{r} -pmap <- std_pmap() -unlist(pmap[pmap$tlgfname == "aet02_1", "req_data", drop = TRUE]) +unlist(std_pmap[std_pmap$tlgfname == "aet02_1", "req_data", drop = TRUE]) ``` Note that you can access the explicit functions with `std_filter_fun` and `std_mutate_fun` @@ -102,7 +100,7 @@ Note that you can access the explicit functions with `std_filter_fun` and `std_m std_filter_fun("aet02_1") ``` -and +and ```{r} diff --git a/vignettes/intended_use.Rmd b/vignettes/intended_use.Rmd index 61ec137fe0..9ce490613d 100644 --- a/vignettes/intended_use.Rmd +++ b/vignettes/intended_use.Rmd @@ -7,7 +7,7 @@ vignette: > %\VignetteIndexEntry{Intended Use of chevron} %\VignetteEncoding{UTF-8} %\VignetteEngine{knitr::rmarkdown} -editor_options: +editor_options: chunk_output_type: console --- @@ -53,19 +53,22 @@ the vignette: lopo_entry <- function(tlgfname, type = c("table", "listing", "graph"), extra_args = NULL, output_id = NULL, main_title, subtitles = NULL, footnotes = NULL, filters = NULL, filename = NULL) { - type <- match.arg(type) + type <- match.arg(type) - if (is.null(output_id)) - output_id <- paste0(substr(type, 1, 1), "_", tolower(substr(tlgfname, 1, 2))) + if (is.null(output_id)) { + output_id <- paste0(substr(type, 1, 1), "_", tolower(substr(tlgfname, 1, 2))) + } - if (is.null(filename)) { - ext <- if (type == "graph") ".pdf" else ".txt" - filename <- paste0(output_id, "__", paste(filters, collapse = "_"), ext) - } - stopifnot(tools::file_ext(filename) %in% c("txt", "pdf")) + if (is.null(filename)) { + ext <- if (type == "graph") ".pdf" else ".txt" + filename <- paste0(output_id, "__", paste(filters, collapse = "_"), ext) + } + stopifnot(tools::file_ext(filename) %in% c("txt", "pdf")) - tibble(tlgfname, type, extra_args = list(extra_args), output_id, main_title, subtitles = list(subtitles), - footnotes = list(footnotes), filters = list(filters), filename) + tibble(tlgfname, type, + extra_args = list(extra_args), output_id, main_title, subtitles = list(subtitles), + footnotes = list(footnotes), filters = list(filters), filename + ) } lopo <- rbind( @@ -83,11 +86,15 @@ lopo <- rbind( tlgfname = "aet02_1", type = "table", main_title = "Adverse Events", footnotes = c( - paste("Investigator text for AEs encoded using MedDRA version {{medra-version}}.", - "Percentages are based on N in the column headings."), - paste("Only treatment emergent AEs are displayed. For frequency counts by preferred term, multiple", - "occurrences of the same AE in an individual are counted only once. For frequency counts of", - "'Total number of events' rows, multiple occurrences of the same AE in an individual are counted separately.") + paste( + "Investigator text for AEs encoded using MedDRA version {{medra-version}}.", + "Percentages are based on N in the column headings." + ), + paste( + "Only treatment emergent AEs are displayed. For frequency counts by preferred term, multiple", + "occurrences of the same AE in an individual are counted only once. For frequency counts of", + "'Total number of events' rows, multiple occurrences of the same AE in an individual are counted separately." + ) ), filters = "SE" ), @@ -95,12 +102,16 @@ lopo <- rbind( tlgfname = "aet02_1", type = "table", main_title = "Adverse Events Leading to Study Treatment Discontinuation", footnotes = c( - paste("Investigator text for AEs encoded using MedDRA version {{medra-version}}.", - "Percentages are based on N in the column headings."), - paste("Only treatment emergent AEs are displayed where the study medication adjustment CRF question is", - "answered as 'Drug withdrawn'. For frequency counts by preferred term, multiple occurrences of the", - "same AE in an individual are counted only once. For frequency counts of 'Total number of events' rows,", - "multiple occurrences of the same AE in an individual are counted separately.") + paste( + "Investigator text for AEs encoded using MedDRA version {{medra-version}}.", + "Percentages are based on N in the column headings." + ), + paste( + "Only treatment emergent AEs are displayed where the study medication adjustment CRF question is", + "answered as 'Drug withdrawn'. For frequency counts by preferred term, multiple occurrences of the", + "same AE in an individual are counted only once. For frequency counts of 'Total number of events' rows,", + "multiple occurrences of the same AE in an individual are counted separately." + ) ), filters = "SE" ), @@ -118,10 +129,14 @@ lopo <- rbind( tlgfname = "lbt01_1", type = "table", main_title = "Listing of Laboratory Data and Change from Baseline by Visit (including CTC grade)", footnotes = c( - paste("Grading displayed is based on numeric thresholds only in NCI CTCAE {{ctc-version}}.", - "NCI CTCAE is the National Cancer Institute Common Terminology Criteria for Adverse Events."), - paste("NCI CTCAE grade is displayed as abnormal high (H) or low (L) from collected range followed", - "by the grade where relevant"), + paste( + "Grading displayed is based on numeric thresholds only in NCI CTCAE {{ctc-version}}.", + "NCI CTCAE is the National Cancer Institute Common Terminology Criteria for Adverse Events." + ), + paste( + "NCI CTCAE grade is displayed as abnormal high (H) or low (L) from collected range followed", + "by the grade where relevant" + ), "CfBL is Change from Baseline. Baseline is the patient’s last observation prior to initiation of study drug." ), filters = "SE", @@ -141,8 +156,10 @@ lopo <- rbind( main_title = "Listing of Laboratory Data and Change from Baseline by Visit (Standardised parameters)", footnotes = c( "Includes values standardised using Roche Safety Lab Standardisation", - paste("Abnormalities displayed as high (H) or low (L) for outside normal range, or high high (HH) or", - "low low (LL) for outside the marked abnormality range with a significant change from baseline"), + paste( + "Abnormalities displayed as high (H) or low (L) for outside normal range, or high high (HH) or", + "low low (LL) for outside the marked abnormality range with a significant change from baseline" + ), "CfBL is Change from Baseline. Baseline is the patient’s last observation prior to initiation of study drug." ), filters = "SE", @@ -154,7 +171,7 @@ lopo <- rbind( Which provides the following LoPO: ```{r} -excerpt <- function(x) lapply(x, function(xi) if (length(xi) > 0)paste(substr(xi[1], 1, 8), "...") else "") +excerpt <- function(x) lapply(x, function(xi) if (length(xi) > 0) paste(substr(xi[1], 1, 8), "...") else "") knitr::kable(lopo %>% mutate(main_title = excerpt(main_title), footnotes = excerpt(footnotes))) ``` @@ -196,7 +213,9 @@ adam_study_data The `lopo` contains the following filter labels: ```{r} -lopo$filters %>% unlist() %>% unique() +lopo$filters %>% + unlist() %>% + unique() ``` Each label corresponds to a particular subsetting operation of a dataset. As there is currently no R package available @@ -214,18 +233,18 @@ new_filter_func <- function(dataname, expr) { # filter label functions flf <- list( - ITT = new_filter_func("adsl", ITTFL == "Y"), - SE = new_filter_func("adsl", SAFFL == "Y"), - CTC35 = new_filter_func("adae", AETOXGR %in% c("3", "4", "5")), - FATAL = new_filter_func("adae", AESDTH == "Y"), - TX = identity + ITT = new_filter_func("adsl", ITTFL == "Y"), + SE = new_filter_func("adsl", SAFFL == "Y"), + CTC35 = new_filter_func("adae", AETOXGR %in% c("3", "4", "5")), + FATAL = new_filter_func("adae", AESDTH == "Y"), + TX = identity ) ``` These filter label based system can then be used as follows, assume we would like the data for `CTC35_SE`: ```{r} -adam__CTC35_SE <- adam_study_data %>% +adam__CTC35_SE <- adam_study_data %>% # nolint flf$SE() %>% flf$CTC35() %>% dm_apply_filters() @@ -245,8 +264,9 @@ dm_filter_with_labels <- function(dm, filter_labels, filter_label_def = get_std_ is.null(filter_labels) || all(filter_labels %in% names(filter_label_def)) ) - if (length(filter_labels) == 0) + if (length(filter_labels) == 0) { return(dm) + } Reduce(function(f1, f2) f2(f1), filter_label_def[filter_labels], init = dm) } @@ -257,8 +277,8 @@ adam_study_data %>% so to get the filtered data -```{r} -adam__CTC35_SE <- adam_study_data %>% +```{r} +adam__CTC35_SE <- adam_study_data %>% # nolint dm_filter_with_labels(c("CTC35", "SE")) %>% dm_apply_filters() @@ -281,7 +301,9 @@ our own functionality: ```{r} render_whiskers <- function(templates, dict = character(0)) { - if (is.null(templates)) return(NULL) + if (is.null(templates)) { + return(NULL) + } stopifnot( is.character(templates) @@ -297,7 +319,9 @@ render_whiskers_string <- function(template, dict = character(0)) { isFALSE(any(duplicated(names(as.list(dict))))) ) - if (length(dict) == 0) return(template) + if (length(dict) == 0) { + return(template) + } ndata <- paste0("{{", names(dict), "}}") for (i in seq_along(dict)) { @@ -378,7 +402,7 @@ dict <- c( main_title_lopo = lopo_1$main_title, population_title = population_title(lopo_1$filters) ) - + deco <- lapply(deco_templ, render_whiskers, dict = dict) ## Data --- @@ -418,7 +442,7 @@ lopo_new <- rbind( ) ) -pmap_new <- append_to_pmap(std_pmap(), pmap_row("ns_dmtspecial", req_data = "adsl")) +pmap_new <- rbind(std_pmap, pmap_row("ns_dmtspecial", req_data = "adsl")) ``` ### Modifying a Standard @@ -429,7 +453,7 @@ ns_aet02_1 <- function(...) { rbind(tbl, tbl) } -pmap_new <- append_to_pmap(pmap_new, pmap_row("ns_aet02_1", req_data = c("adsl", "adae"))) +pmap_new <- rbind(pmap_new, pmap_row("ns_aet02_1", req_data = c("adsl", "adae"))) ``` ## Creating Many Outputs @@ -450,7 +474,6 @@ std_deco_templ <- function(lopo_row) { create_one_tlg <- function(lopoi, adam_db, pmap = std_map(), deco_template_fun = std_deco_templ, dict = character(), filter_label_def = get_std_filter_label_defn()) { - db <- adam_db %>% dm_filter_with_labels(lopoi$filters) %>% preprocess_data(lopoi$tlgfname, pmap = pmap) @@ -467,16 +490,16 @@ create_one_tlg <- function(lopoi, adam_db, pmap = std_map(), deco_template_fun = ## Create Output do.call(lopoi$tlgfname, c(list(adam_db = db, deco = deco), lopoi$extra_args)) - } create_tlg_in_lopo <- function(adam_db, lopo, pmap = std_map(), deco_template_fun = std_deco_templ, dict = character(), filter_label_def = get_std_filter_label_defn()) { - setNames(lapply(purrr::transpose(lopo), - create_one_tlg, adam_db, pmap = pmap, - deco_template_fun = deco_template_fun, - dict = dict, filter_label_def = filter_label_def), lopo$filename) + create_one_tlg, adam_db, + pmap = pmap, + deco_template_fun = deco_template_fun, + dict = dict, filter_label_def = filter_label_def + ), lopo$filename) } ```