Skip to content

Commit

Permalink
lots of fixes for R CMD CHECK
Browse files Browse the repository at this point in the history
  • Loading branch information
DanChaltiel committed Aug 9, 2024
1 parent 5f57b2d commit 3531f43
Show file tree
Hide file tree
Showing 28 changed files with 133 additions and 106 deletions.
3 changes: 0 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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'
4 changes: 1 addition & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions R/EDCimport-package.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"))




16 changes: 9 additions & 7 deletions R/ae_table_grade.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
#'
Expand All @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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.
#'
Expand Down
50 changes: 26 additions & 24 deletions R/ae_table_soc.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion R/crf_status.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() %>%
Expand Down
2 changes: 1 addition & 1 deletion R/sanity_checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...,
Expand Down
7 changes: 5 additions & 2 deletions R/search_for_newer_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion R/waterfall_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
8 changes: 5 additions & 3 deletions man/ae_plot_grade.Rd

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

8 changes: 5 additions & 3 deletions man/ae_plot_grade_max.Rd

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

4 changes: 2 additions & 2 deletions man/ae_plot_grade_sum.Rd

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

Loading

0 comments on commit 3531f43

Please sign in to comment.