diff --git a/DESCRIPTION b/DESCRIPTION index ae49369..20e297f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,14 +72,11 @@ Collate: 'options.R' 'population_plot.R' 'project.R' - 'recist_check.R' 'sanity_checks.R' 'sas_format.R' 'save_to_excel.R' 'search_for_newer_data.R' 'split_mixed.R' 'swimmerplot.R' - 'todo_base_macro.R' - 'todo_read_all_csv.R' 'trialmaster.R' 'waterfall_plot.R' diff --git a/NAMESPACE b/NAMESPACE index 2a0d07c..054d640 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -76,6 +76,7 @@ importFrom(cli,cli_inform) importFrom(cli,cli_vec) importFrom(cli,cli_warn) importFrom(cli,col_green) +importFrom(cli,col_red) importFrom(cli,format_inline) importFrom(cli,qty) importFrom(cli,rule) @@ -112,7 +113,6 @@ importFrom(dplyr,rename) importFrom(dplyr,rename_with) importFrom(dplyr,rowwise) importFrom(dplyr,select) -importFrom(dplyr,semi_join) importFrom(dplyr,setdiff) importFrom(dplyr,slice) importFrom(dplyr,slice_max) @@ -212,7 +212,6 @@ importFrom(rlang,current_env) importFrom(rlang,enquo) importFrom(rlang,enquos) importFrom(rlang,ensym) -importFrom(rlang,env) importFrom(rlang,have_name) importFrom(rlang,int) importFrom(rlang,is_empty) @@ -254,7 +253,6 @@ importFrom(tibble,deframe) importFrom(tibble,lst) importFrom(tibble,tibble) importFrom(tidyr,build_wider_spec) -importFrom(tidyr,fill) importFrom(tidyr,pivot_longer) importFrom(tidyr,pivot_wider_spec) importFrom(tidyr,replace_na) diff --git a/R/EDCimport-package.R b/R/EDCimport-package.R index ff94816..44fc970 100644 --- a/R/EDCimport-package.R +++ b/R/EDCimport-package.R @@ -1,7 +1,7 @@ #' @keywords internal #' @importFrom dplyr %>% #' @importFrom rlang %||% := -#' @importFrom cli qty col_green +#' @importFrom cli qty col_green col_red "_PACKAGE" ## usethis namespace: start @@ -27,7 +27,8 @@ edcimport_env = rlang::new_environment() edcimport_env$warn_list = list() edcimport_env$lookup = NULL -utils::globalVariables(c(".", ":=", "!!", ".data", ".env", "SUBJID", "age", "dataset", "n_id", "name", "value", ".id", "aegr", "aesoc", "best_resp", "case_when", "diff_first", "element_blank", "facet_grid", "first_sum", "grade2", "grade_max", "last_sum", "min_sum", "n_ae", "n_arm", "n_soc", "n_term", "replace_na", "resp", "resp_num", "sae", "scale_fill_steps", "star", "star_txt", "subjid", "variable", "vars", "x", "column", "last_date", "origin", "pct_datasets", "arm_", "grade_", "soc_", "subjid_", "term_", "any_ae", "any_severe", "label", "label_percent_positive", "n_severe", "pct_ae", "pct_severe", "severe_", "unit")) +utils::globalVariables(c(".", ":=", "!!", ".data", ".env", "SUBJID", "age", "dataset", "n_id", "name", "value", ".id", "aegr", "aesoc", "best_resp", "case_when", "diff_first", "element_blank", "facet_grid", "first_sum", "grade2", "grade_max", "last_sum", "min_sum", "n_ae", "n_arm", "n_soc", "n_term", "replace_na", "resp", "resp_num", "sae", "scale_fill_steps", "star", "star_txt", "subjid", "variable", "vars", "x", "column", "last_date", "origin", "pct_datasets", "arm_", "grade_", "soc_", "subjid_", "term_", "any_ae", "any_severe", "label", "label_percent_positive", "n_severe", "pct_ae", "pct_severe", "severe_", "unit", ".name", "Tot", "any_grade_sup_na", "calc", "col_keys", "crfstat", "datetime_extraction", "first_date", "h1", "h2", "origin_col", "origin_data", "origin_label", "prefered", "resp2", "showNA", "sort_by_count", "title", "weight")) + diff --git a/R/ae_table_grade.R b/R/ae_table_grade.R index 93cc030..f28cccd 100644 --- a/R/ae_table_grade.R +++ b/R/ae_table_grade.R @@ -8,7 +8,6 @@ #' Summary tables for AE #' -#' @param type one or several of `c("max", "sup", "eq")`. `max` computes the maximum AE grade per patient, `sup` computes the number of patients having experienced at least one AE of grade higher or equal to X, and `eq` computes the number of patients having experienced at least one AE of grade equal to X. #' @param percent whether to show percentages with counts. Defaults to TRUE. Can also be "only" to not show counts. #' @inheritParams ae_table_soc #' @inherit ae_table_soc seealso @@ -23,10 +22,11 @@ #' @export #' #' @examples -#' \dontrun{ #' tm = edc_example_ae() #' load_list(tm) #' +#' if(require(flextable)){ +#' #' ae_table_grade(df_ae=ae, df_enrol=enrolres, arm=NULL) %>% #' as_flextable(header_show_n=TRUE) #' @@ -38,8 +38,9 @@ #' ae %>% #' filter(sae=="Yes") %>% #' ae_table_grade(df_enrol=enrolres, arm="ARM") %>% -#' mutate_all(~str_replace(.x, "AE", "SAE")) %>% +#' dplyr::mutate_all(~stringr::str_replace(.x, "AE", "SAE")) %>% #' as_flextable(header_show_n=TRUE) +#' #' } ae_table_grade = function( df_ae, ..., df_enrol, @@ -94,10 +95,10 @@ ae_table_grade = function( any_grade_sup_na = case_when(!cur_group()$subjid %in% df_ae$subjid ~ lab_no_ae, any(is.na(grade), na.rm=TRUE) ~ "Any missing grade", .default="foobar"),, - any_grade_sup_1 = ifelse(any(grade >= 1, na.rm=TRUE), "Grade ≥ 1", "foobar"), - any_grade_sup_2 = ifelse(any(grade >= 2, na.rm=TRUE), "Grade ≥ 2", "foobar"), - any_grade_sup_3 = ifelse(any(grade >= 3, na.rm=TRUE), "Grade ≥ 3", "foobar"), - any_grade_sup_4 = ifelse(any(grade >= 4, na.rm=TRUE), "Grade ≥ 4", "foobar"), + any_grade_sup_1 = ifelse(any(grade >= 1, na.rm=TRUE), "Grade \u2265 1", "foobar"), + any_grade_sup_2 = ifelse(any(grade >= 2, na.rm=TRUE), "Grade \u2265 2", "foobar"), + any_grade_sup_3 = ifelse(any(grade >= 3, na.rm=TRUE), "Grade \u2265 3", "foobar"), + any_grade_sup_4 = ifelse(any(grade >= 4, na.rm=TRUE), "Grade \u2265 4", "foobar"), any_grade_sup_5 = ifelse(any(grade >= 5, na.rm=TRUE), "Grade = 5", "foobar"), any_grade_eq_na = any_grade_sup_na, any_grade_eq_1 = ifelse(any(grade == 1, na.rm=TRUE), "Grade 1", "foobar"), @@ -472,6 +473,7 @@ ae_table_grade_max = function( #' #' @inheritParams ae_table_soc #' @inherit ae_table_soc seealso +#' @param proportion display proportion instead of count. #' @param type the plots to be included. One of `c("stack", "dodge", "fill")`. #' @param drop_levels whether to drop unused grade levels. #' diff --git a/R/ae_table_soc.R b/R/ae_table_soc.R index 191470f..901c2f5 100644 --- a/R/ae_table_soc.R +++ b/R/ae_table_soc.R @@ -8,27 +8,37 @@ #' The function `ae_table_soc()` creates a summary table of maximum AE grades for each patient according to term and SOC CTCAE. #' The resulting dataframe can be piped to `as_flextable()` to get a nicely formatted flextable. #' -#' @param df_ae adverse event dataset, one row per AE, containing subjid, soc, and grade +#' @param df_ae adverse event dataset, one row per AE, containing subjid, soc, and grade. #' @param df_enrol enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset. -#' @param subjid name of the patient ID in both `df_ae` and `df_enrol`. Case-insensitive. -#' @param arm name of the treatment column in `df_enrol`. Case-insensitive. Can be set to `NULL` to not group. -#' @param grade name of the AE grade column in `df_ae`. Case-insensitive. -#' @param soc name of the SOC column in `df_ae`. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from `df_ae`). +#' @param variant one or several of `c("max", "sup", "eq")`. `max` computes the maximum AE grade per patient, `sup` computes the number of patients having experienced at least one AE of grade higher or equal to X, and `eq` computes the number of patients having experienced at least one AE of grade equal to X. +#' @param arm name of the treatment column in `df_enrol`. Case-insensitive. Can be set to `NULL`. #' @param term name of the the CTCAE term column in `df_ae`. Case-insensitive. Can be set to `NULL`. -#' @param sort_by_ae should the table be sorted by number or alphabetically -#' @param total whether to add a `total` column for each arm -#' @param digits significant digits for percentages -#' @param warn_miss whether to warn for missing values +#' @param sort_by_count should the table be sorted by the number of AE or by SOC alphabetically. +#' @param total whether to add a `total` column for each arm. +#' @param showNA whether to display missing grades. +#' @param digits significant digits for percentages. +#' @param warn_miss whether to warn for missing values. +#' @param grade name of the AE grade column in `df_ae`. Case-insensitive. +#' @param soc name of the SOC column in `df_ae`. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from `df_ae`). +#' @param subjid name of the patient ID in both `df_ae` and `df_enrol`. Case-insensitive. #' @param ... unused #' #' @return a dataframe (`ae_table_soc()`) or a flextable (`as_flextable()`). #' #' @seealso [ae_table_grade_max()], [ae_table_grade_n()], [ae_table_soc()], [ae_plot_grade_max()], [ae_plot_grade_n()] #' +#' @importFrom cli cli_warn +#' @importFrom dplyr across any_of arrange count cur_group filter full_join if_else mutate pull rename select summarise +#' @importFrom forcats fct_infreq +#' @importFrom glue glue +#' @importFrom purrr iwalk keep map +#' @importFrom rlang arg_match check_dots_empty ensym is_empty set_names +#' @importFrom tibble deframe lst +#' @importFrom tidyr build_wider_spec pivot_wider_spec unnest +#' @importFrom tidyselect matches #' @export #' -#' @examples -#' +#' @examples #' tm = edc_example_ae() #' ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL) #' ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL, arm=NULL) @@ -46,20 +56,12 @@ #' as_flextable() %>% #' highlight(i=~soc=="Hepatobiliary disorders", j="all_patients_Tot") #' } -#' @importFrom cli cli_warn -#' @importFrom dplyr across any_of arrange count cur_group filter full_join if_else mutate pull rename select summarise -#' @importFrom forcats fct_infreq -#' @importFrom glue glue -#' @importFrom purrr iwalk keep map -#' @importFrom rlang arg_match check_dots_empty ensym is_empty set_names -#' @importFrom tibble deframe lst -#' @importFrom tidyr build_wider_spec pivot_wider_spec unnest -#' @importFrom tidyselect matches ae_table_soc = function( df_ae, ..., df_enrol, variant=c("max", "sup", "eq"), - arm=NULL, grade="AEGR", soc="AESOC", term=NULL, subjid="SUBJID", - sort_by_count=TRUE, total=TRUE, showNA=TRUE, digits=0, warn_miss=FALSE + arm=NULL, term=NULL, + sort_by_count=TRUE, total=TRUE, showNA=TRUE, digits=0, warn_miss=FALSE, + grade="AEGR", soc="AESOC", subjid="SUBJID" ){ check_dots_empty() default_arm = set_label("All patients", "Treatment arm") @@ -286,7 +288,7 @@ as_flextable.ae_table_soc = function(x, #' #' ae2 %>% #' butterfly_plot(df_enrol=enrolres, severe="serious") + -#' labs(caption="Darker areas represent Serious Adverse Events") +#' ggplot2::labs(caption="Darker areas represent Serious Adverse Events") butterfly_plot = function( df_ae, ..., df_enrol, severe=NULL, sort_by=c("total", "severe"), range_min=NULL, arm="ARM", subjid="SUBJID", soc="AESOC" @@ -381,7 +383,7 @@ butterfly_plot = function( #' @rdname butterfly_plot -#' @usage ae_plot_soc(...) +#' @usage ae_plot_soc(df_ae, ..., df_enrol, severe, sort_by, range_min, arm, subjid, soc) #' @export ae_plot_soc = butterfly_plot diff --git a/R/crf_status.R b/R/crf_status.R index 5400315..4dc2270 100644 --- a/R/crf_status.R +++ b/R/crf_status.R @@ -11,6 +11,7 @@ #' @param crfstat_lvls the CRF status levels, from "best" to "worst". The plot is ordered by the "worst" level. #' @param x_label a glue pattern determining the tick label in the x axis. Available variables are `c("nrow", "ncol", "n_id", "rows_per_id", "crfname")`, taken from [edc_lookup()]. #' @param treat_as_worst a regex for levels that should be treated as worst in the ordering +#' @param ... unused #' #' @return a ggplot #' @export @@ -83,7 +84,7 @@ crf_status_plot = function(crfstat_col="CRFSTAT", #' @rdname crf_status_plot #' @export -#' @source ggsci:::ggsci_db$lancet[["lanonc"]] %>% dput() +#' @source `ggsci:::ggsci_db$lancet[["lanonc"]] %>% dput()` edc_pal_crf = function(){ c("Complete"="#000e8b", "Complete Locked"="#0053a5", diff --git a/R/helpers.R b/R/helpers.R index 16ba59a..27f857b 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -108,7 +108,7 @@ find_keyword = function(keyword, data=edc_lookup(), ignore_case=TRUE){ #' #' x #' #y and z are left untouched (or throw an error if fail=TRUE) -#' mutate_all(x, fct_yesno, fail=FALSE) +#' sapply(x, fct_yesno, fail=FALSE) #' #' # as "1-Yes" is not in `input`, x$e is untouched/fails if strict=TRUE #' fct_yesno(x$e) @@ -316,11 +316,13 @@ edc_inform_code = function(main="main.R", Rdir="R/"){ #' #' @return nothing #' @export -#' -#' @examples -#' save_sessioninfo() #' @importFrom fs dir_create path path_dir path_ext path_ext_remove #' @importFrom utils capture.output sessionInfo +#' +#' @examples +#' \dontrun{ +#' save_sessioninfo() +#' } save_sessioninfo = function(path="check/session_info.txt", with_date=TRUE){ target = path %>% path_ext_remove() %>% diff --git a/R/sanity_checks.R b/R/sanity_checks.R index 023ca8a..352b586 100644 --- a/R/sanity_checks.R +++ b/R/sanity_checks.R @@ -234,7 +234,7 @@ edc_data_warn = function(df, message, ..., } #' @rdname edc_data_warn -#' @usage edc_data_stop(...) #same arguments +#' @usage edc_data_stop(df, message, ..., issue_n, max_subjid, csv_path, col_subjid) #' @export #' @importFrom rlang check_dots_empty edc_data_stop = function(df, message, ..., diff --git a/R/search_for_newer_data.R b/R/search_for_newer_data.R index 1ba4298..9d9dbd5 100644 --- a/R/search_for_newer_data.R +++ b/R/search_for_newer_data.R @@ -4,11 +4,12 @@ #' #' Search in some folders if a TrialMaster database more recent than the current extration is present. By default, it will search the "data" folder and the OS usual "Downloads" folder. If a newer database is found, user will be asked if they want to move it to the "data" folder. #' -#' @param project archive path, giving the project name +#' @param archive TM archive path, giving the project name and date #' @param source the path vector to be searched, default to both "data" and the usual "Downloads" folder #' @param target the path where files should be copied #' @param ask whether to ask the user to move the file to "data" #' @param advice whether to advice how to move it instead, if `ask==FALSE` +#' @param ... unused #' #' @return the path to the newer file, invisibly. #' @export @@ -22,7 +23,9 @@ #' #' @examples #' \dontrun{ -#' +#' archive = "data/MYPROJECT_ExportTemplate_xxx_SAS_XPORT_2024_06_01_12_00.zip" +#' #tm = read_trialmaster(archive) +#' search_for_newer_data(archive) #' } search_for_newer_data = function(archive, ..., source=path_home("Downloads"), diff --git a/R/utils.R b/R/utils.R index 9fcc35a..e1eb957 100644 --- a/R/utils.R +++ b/R/utils.R @@ -91,7 +91,7 @@ deprecatedly = function(f, what, when, with=caller_arg(f), details=NULL, type="w #' @source https://github.com/r-lib/cli/issues/228#issuecomment-1453614104 #' @importFrom rlang caller_env cli_menu <- function(prompt, not_interactive, choices, quit = integer(), .envir = caller_env()) { - if (!cli:::is_interactive()) { + if (!interactive()) { cli::cli_abort(c(prompt, not_interactive), .envir = .envir) } choices <- sapply(choices, cli::format_inline, .envir = .envir, USE.NAMES = FALSE) diff --git a/R/waterfall_plot.R b/R/waterfall_plot.R index 9e3e995..470af4b 100644 --- a/R/waterfall_plot.R +++ b/R/waterfall_plot.R @@ -34,7 +34,8 @@ #' rc %>% #' left_join(enrolres, by="SUBJID") %>% #adds the ARM column #' mutate(new_lesion = ifelse(RCNEW=="1-Yes", "New lesion", NA)) %>% -#' waterfall_plot(rc_date="RCDT", rc_sum="RCTLSUM", rc_resp="RCRESP", arm="ARM", rc_star="new_lesion") +#' waterfall_plot(rc_date="RCDT", rc_sum="RCTLSUM", rc_resp="RCRESP", +#' arm="ARM", rc_star="new_lesion") #'} waterfall_plot = function(data_recist, rc_sum="RCTLSUM", rc_resp="RCRESP", rc_date="RCDT", type = c("best_resp", "worst_resp"), diff --git a/man/ae_plot_grade.Rd b/man/ae_plot_grade.Rd index 24d21f9..64221d9 100644 --- a/man/ae_plot_grade.Rd +++ b/man/ae_plot_grade.Rd @@ -18,23 +18,25 @@ ae_plot_grade( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} \item{df_enrol}{enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.} +\item{variant}{one or several of \code{c("max", "sup", "eq")}. \code{max} computes the maximum AE grade per patient, \code{sup} computes the number of patients having experienced at least one AE of grade higher or equal to X, and \code{eq} computes the number of patients having experienced at least one AE of grade equal to X.} + \item{position}{Position adjustment (cf. \code{\link[ggplot2:geom_bar]{ggplot2::geom_col()}})} \item{type}{whether to present patients as proportions (\code{relative}) or as counts (\code{absolute})} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} \item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} -\item{total}{whether to add a \code{total} column for each arm} +\item{total}{whether to add a \code{total} column for each arm.} } \value{ a ggplot diff --git a/man/ae_plot_grade_max.Rd b/man/ae_plot_grade_max.Rd index f759634..6241b1f 100644 --- a/man/ae_plot_grade_max.Rd +++ b/man/ae_plot_grade_max.Rd @@ -18,7 +18,7 @@ ae_plot_grade_max( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} @@ -26,13 +26,15 @@ ae_plot_grade_max( \item{type}{the plots to be included. One of \code{c("stack", "dodge", "fill")}.} +\item{proportion}{display proportion instead of count.} + \item{drop_levels}{whether to drop unused grade levels.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} -\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from \code{df_ae}).} +\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from \code{df_ae}).} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} } diff --git a/man/ae_plot_grade_sum.Rd b/man/ae_plot_grade_sum.Rd index ca05f2f..c766e19 100644 --- a/man/ae_plot_grade_sum.Rd +++ b/man/ae_plot_grade_sum.Rd @@ -18,7 +18,7 @@ ae_plot_grade_sum( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} @@ -30,7 +30,7 @@ ae_plot_grade_sum( \item{weights}{(optional) a length 5 numeric vector, giving the weights of each grade} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} diff --git a/man/ae_table_grade.Rd b/man/ae_table_grade.Rd index ca1ca20..40cfb19 100644 --- a/man/ae_table_grade.Rd +++ b/man/ae_table_grade.Rd @@ -17,13 +17,15 @@ ae_table_grade( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} \item{df_enrol}{enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{variant}{one or several of \code{c("max", "sup", "eq")}. \code{max} computes the maximum AE grade per patient, \code{sup} computes the number of patients having experienced at least one AE of grade higher or equal to X, and \code{eq} computes the number of patients having experienced at least one AE of grade equal to X.} + +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} @@ -31,9 +33,7 @@ ae_table_grade( \item{percent}{whether to show percentages with counts. Defaults to TRUE. Can also be "only" to not show counts.} -\item{total}{whether to add a \code{total} column for each arm} - -\item{type}{one or several of \code{c("max", "sup", "eq")}. \code{max} computes the maximum AE grade per patient, \code{sup} computes the number of patients having experienced at least one AE of grade higher or equal to X, and \code{eq} computes the number of patients having experienced at least one AE of grade equal to X.} +\item{total}{whether to add a \code{total} column for each arm.} } \value{ a crosstable @@ -42,10 +42,11 @@ a crosstable Summary tables for AE } \examples{ -\dontrun{ tm = edc_example_ae() load_list(tm) +if(require(flextable)){ + ae_table_grade(df_ae=ae, df_enrol=enrolres, arm=NULL) \%>\% as_flextable(header_show_n=TRUE) @@ -57,8 +58,9 @@ library(dplyr) ae \%>\% filter(sae=="Yes") \%>\% ae_table_grade(df_enrol=enrolres, arm="ARM") \%>\% - mutate_all(~str_replace(.x, "AE", "SAE")) \%>\% + dplyr::mutate_all(~stringr::str_replace(.x, "AE", "SAE")) \%>\% as_flextable(header_show_n=TRUE) + } } \seealso{ diff --git a/man/ae_table_grade_max.Rd b/man/ae_table_grade_max.Rd index 9db4006..fd35035 100644 --- a/man/ae_table_grade_max.Rd +++ b/man/ae_table_grade_max.Rd @@ -17,23 +17,23 @@ ae_table_grade_max( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} \item{df_enrol}{enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} -\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from \code{df_ae}).} +\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from \code{df_ae}).} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} -\item{total}{whether to add a \code{total} column for each arm} +\item{total}{whether to add a \code{total} column for each arm.} -\item{digits}{significant digits for percentages} +\item{digits}{significant digits for percentages.} } \value{ a crosstable (dataframe) diff --git a/man/ae_table_grade_n.Rd b/man/ae_table_grade_n.Rd index 6ed6f22..4a5558b 100644 --- a/man/ae_table_grade_n.Rd +++ b/man/ae_table_grade_n.Rd @@ -17,23 +17,23 @@ ae_table_grade_n( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} \item{df_enrol}{enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} \item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} -\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from \code{df_ae}).} +\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from \code{df_ae}).} -\item{total}{whether to add a \code{total} column for each arm} +\item{total}{whether to add a \code{total} column for each arm.} -\item{digits}{significant digits for percentages} +\item{digits}{significant digits for percentages.} } \value{ a crosstable diff --git a/man/ae_table_soc.Rd b/man/ae_table_soc.Rd index f062e03..dfc686b 100644 --- a/man/ae_table_soc.Rd +++ b/man/ae_table_soc.Rd @@ -11,15 +11,15 @@ ae_table_soc( df_enrol, variant = c("max", "sup", "eq"), arm = NULL, - grade = "AEGR", - soc = "AESOC", term = NULL, - subjid = "SUBJID", sort_by_count = TRUE, total = TRUE, showNA = TRUE, digits = 0, - warn_miss = FALSE + warn_miss = FALSE, + grade = "AEGR", + soc = "AESOC", + subjid = "SUBJID" ) \method{as_flextable}{ae_table_soc}( @@ -29,35 +29,39 @@ ae_table_soc( ) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} \item{df_enrol}{enrollment dataset, one row per patient, containing subjid (and arm if needed). All patients should be in this dataset.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{variant}{one or several of \code{c("max", "sup", "eq")}. \code{max} computes the maximum AE grade per patient, \code{sup} computes the number of patients having experienced at least one AE of grade higher or equal to X, and \code{eq} computes the number of patients having experienced at least one AE of grade equal to X.} -\item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} - -\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from \code{df_ae}).} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{term}{name of the the CTCAE term column in \code{df_ae}. Case-insensitive. Can be set to \code{NULL}.} -\item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} +\item{sort_by_count}{should the table be sorted by the number of AE or by SOC alphabetically.} + +\item{total}{whether to add a \code{total} column for each arm.} -\item{total}{whether to add a \code{total} column for each arm} +\item{showNA}{whether to display missing grades.} -\item{digits}{significant digits for percentages} +\item{digits}{significant digits for percentages.} -\item{warn_miss}{whether to warn for missing values} +\item{warn_miss}{whether to warn for missing values.} + +\item{grade}{name of the AE grade column in \code{df_ae}. Case-insensitive.} + +\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from \code{df_ae}).} + +\item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} \item{x}{a dataframe, resulting of \code{ae_table_soc()}} \item{arm_colors}{colors for the arm groups} \item{padding_v}{a numeric of lenght up to 2, giving the vertical padding of body (1) and header (2)} - -\item{sort_by_ae}{should the table be sorted by number or alphabetically} } \value{ a dataframe (\code{ae_table_soc()}) or a flextable (\code{as_flextable()}). @@ -69,7 +73,6 @@ The function \code{ae_table_soc()} creates a summary table of maximum AE grades The resulting dataframe can be piped to \code{as_flextable()} to get a nicely formatted flextable. } \examples{ - tm = edc_example_ae() ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL) ae_table_soc(df_ae=tm$ae, df_enrol=tm$enrolres, term=NULL, arm=NULL) diff --git a/man/butterfly_plot.Rd b/man/butterfly_plot.Rd index 1a903ed..c75c199 100644 --- a/man/butterfly_plot.Rd +++ b/man/butterfly_plot.Rd @@ -17,10 +17,10 @@ butterfly_plot( soc = "AESOC" ) -ae_plot_soc(...) +ae_plot_soc(df_ae, ..., df_enrol, severe, sort_by, range_min, arm, subjid, soc) } \arguments{ -\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade} +\item{df_ae}{adverse event dataset, one row per AE, containing subjid, soc, and grade.} \item{...}{unused} @@ -32,11 +32,11 @@ ae_plot_soc(...) \item{range_min}{The minimum value for the upper limit of the x-axis range. Set to \code{1} to always include 100\%.} -\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL} to not group.} +\item{arm}{name of the treatment column in \code{df_enrol}. Case-insensitive. Can be set to \code{NULL}.} \item{subjid}{name of the patient ID in both \code{df_ae} and \code{df_enrol}. Case-insensitive.} -\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing(e.g. if patient if absent from \code{df_ae}).} +\item{soc}{name of the SOC column in \code{df_ae}. Case-insensitive. Grade will be considered 0 if missing (e.g. if patient if absent from \code{df_ae}).} } \value{ a crosstable (dataframe) @@ -61,7 +61,7 @@ ae2 \%>\% ae2 \%>\% butterfly_plot(df_enrol=enrolres, severe="serious") + - labs(caption="Darker areas represent Serious Adverse Events") + ggplot2::labs(caption="Darker areas represent Serious Adverse Events") } \seealso{ \code{\link[=ae_table_grade_max]{ae_table_grade_max()}}, \code{\link[=ae_table_grade_n]{ae_table_grade_n()}}, \code{\link[=ae_table_soc]{ae_table_soc()}}, \code{\link[=ae_plot_grade_max]{ae_plot_grade_max()}}, \code{\link[=ae_plot_grade_n]{ae_plot_grade_n()}} diff --git a/man/crf_status_plot.Rd b/man/crf_status_plot.Rd index 74bd482..6a407ff 100644 --- a/man/crf_status_plot.Rd +++ b/man/crf_status_plot.Rd @@ -5,7 +5,7 @@ \alias{edc_pal_crf} \title{Show the current CRF status distribution} \source{ -ggsci:::ggsci_db$lancet[\link{"lanonc"}] \%>\% dput() +\code{ggsci:::ggsci_db$lancet[["lanonc"]] \%>\% dput()} } \usage{ crf_status_plot( @@ -23,6 +23,8 @@ edc_pal_crf() \arguments{ \item{crfstat_col}{the column name of the CRF status} +\item{...}{unused} + \item{details}{whether to show all the CRF status levels. When \code{FALSE} (default), recode the status into "Complete", "Incomplete", or "No Data".} \item{pal}{the palette, defaulting to the helper \code{EDCimport:::edc_pal_crf()}} diff --git a/man/edc_data_warn.Rd b/man/edc_data_warn.Rd index a055a93..d64c720 100644 --- a/man/edc_data_warn.Rd +++ b/man/edc_data_warn.Rd @@ -17,7 +17,7 @@ edc_data_warn( col_subjid = get_subjid_cols() ) -edc_data_stop(...) #same arguments +edc_data_stop(df, message, ..., issue_n, max_subjid, csv_path, col_subjid) edc_data_warnings() } diff --git a/man/fct_yesno.Rd b/man/fct_yesno.Rd index 2dcfc92..fe7ed58 100644 --- a/man/fct_yesno.Rd +++ b/man/fct_yesno.Rd @@ -51,7 +51,7 @@ x = tibble( x #y and z are left untouched (or throw an error if fail=TRUE) -mutate_all(x, fct_yesno, fail=FALSE) +sapply(x, fct_yesno, fail=FALSE) # as "1-Yes" is not in `input`, x$e is untouched/fails if strict=TRUE fct_yesno(x$e) diff --git a/man/save_sessioninfo.Rd b/man/save_sessioninfo.Rd index 8e318ea..c3a8ae8 100644 --- a/man/save_sessioninfo.Rd +++ b/man/save_sessioninfo.Rd @@ -18,5 +18,7 @@ nothing Save \code{sessionInfo()} output into a text file. } \examples{ -save_sessioninfo() +\dontrun{ + save_sessioninfo() +} } diff --git a/man/search_for_newer_data.Rd b/man/search_for_newer_data.Rd index b13ca8f..f906f5b 100644 --- a/man/search_for_newer_data.Rd +++ b/man/search_for_newer_data.Rd @@ -14,6 +14,10 @@ search_for_newer_data( ) } \arguments{ +\item{archive}{TM archive path, giving the project name and date} + +\item{...}{unused} + \item{source}{the path vector to be searched, default to both "data" and the usual "Downloads" folder} \item{target}{the path where files should be copied} @@ -21,8 +25,6 @@ search_for_newer_data( \item{ask}{whether to ask the user to move the file to "data"} \item{advice}{whether to advice how to move it instead, if \code{ask==FALSE}} - -\item{project}{archive path, giving the project name} } \value{ the path to the newer file, invisibly. @@ -32,6 +34,8 @@ Search in some folders if a TrialMaster database more recent than the current ex } \examples{ \dontrun{ - + archive = "data/MYPROJECT_ExportTemplate_xxx_SAS_XPORT_2024_06_01_12_00.zip" + #tm = read_trialmaster(archive) + search_for_newer_data(archive) } } diff --git a/man/waterfall_plot.Rd b/man/waterfall_plot.Rd index 2380532..1e0d398 100644 --- a/man/waterfall_plot.Rd +++ b/man/waterfall_plot.Rd @@ -51,6 +51,7 @@ waterfall_plot(rc, rc_date="RCDT", rc_sum="RCTLSUM", rc_resp="RCRESP", type="wor rc \%>\% left_join(enrolres, by="SUBJID") \%>\% #adds the ARM column mutate(new_lesion = ifelse(RCNEW=="1-Yes", "New lesion", NA)) \%>\% - waterfall_plot(rc_date="RCDT", rc_sum="RCTLSUM", rc_resp="RCRESP", arm="ARM", rc_star="new_lesion") + waterfall_plot(rc_date="RCDT", rc_sum="RCTLSUM", rc_resp="RCRESP", + arm="ARM", rc_star="new_lesion") } } diff --git a/tests/testthat/helper-init.R b/tests/testthat/helper-init.R index f128790..020cb33 100644 --- a/tests/testthat/helper-init.R +++ b/tests/testthat/helper-init.R @@ -36,7 +36,9 @@ library(fs, warn.conflicts=FALSE) library(usethis, warn.conflicts=FALSE) library(rlang, warn.conflicts=FALSE) library(cli, warn.conflicts=FALSE) -library(tidyverse, warn.conflicts=FALSE) +library(dplyr, warn.conflicts=FALSE) +library(purrr, warn.conflicts=FALSE) +# library(tidyverse, warn.conflicts=FALSE) # edc_options( diff --git a/tests/testthat/test-init_project.R b/tests/testthat/test-init_project.R index 34ce78e..061d397 100644 --- a/tests/testthat/test-init_project.R +++ b/tests/testthat/test-init_project.R @@ -1,9 +1,8 @@ - +skip_if(is_checking()) test_that("edc_new_project works", { path = tempdir() %>% paste0("/test/test_init_project.dir") - # browseURL(path) edc_new_project(path, open=FALSE) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 0ad89ad..f8d8680 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -5,6 +5,7 @@ edc_options(edc_lookup_overwrite_warn=FALSE) test_that("no exports", { + skip_if(is_checking()) testthat::test_path("../../R/utils.R") %>% readLines() %>% str_subset("@export") %>% expect_length(0) })