From 9f0b455b7263971f6111807ac0db734a34735ad2 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 10:58:57 +0000 Subject: [PATCH 01/11] refactor: ability to pass params to run_app --- R/run_app.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/run_app.R b/R/run_app.R index fa17f52..9111a88 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -3,6 +3,8 @@ #' List of functions imported for the shiny application. #' When adding new imports, please keep the alphabetical order, at lest for packages. #' +#' @param ... Arguments passed to `shiny::runApp()` +#' #' @import shiny #' @importFrom dplyr mutate filter select group_by summarise pull arrange ungroup #' @importFrom dplyr rename_with across case_when left_join rename @@ -24,6 +26,6 @@ #' @importFrom utils read.csv write.csv #' @importFrom zip zipr #' @export -run_app <- function() { - shiny::runApp(system.file("shiny", package = "aNCA")) +run_app <- function(...) { + shiny::runApp(system.file("shiny", package = "aNCA"), ...) } From 668ad7a56749d1e92d614997612eea825176e073 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:02:05 +0000 Subject: [PATCH 02/11] docs: add missing importFrom to run_app --- R/run_app.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/run_app.R b/R/run_app.R index 9111a88..97e84fd 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -11,6 +11,7 @@ #' @importFrom DT DTOutput renderDataTable datatable formatStyle styleEqual #' @importFrom ggplot2 ggplot geom_errorbar geom_point geom_line labs aes facet_wrap #' @importFrom htmlwidgets JS +#' @importFrom logger log_trace log_debug log_info log_warn log_error log_fatal #' @importFrom PKNCA PKNCAconc PKNCAdose PKNCAdata pk.nca PKNCA.options pknca_units_table #' @importFrom plotly plotlyOutput renderPlotly plotly_build event_data #' @importFrom reactable reactable reactableOutput renderReactable colDef reactableTheme From 8606eced84bffee895cb47cec536beb9bfeb665c Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:02:16 +0000 Subject: [PATCH 03/11] refactor: load libraries inside run_app --- R/run_app.R | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/R/run_app.R b/R/run_app.R index 97e84fd..790f9ca 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -28,5 +28,22 @@ #' @importFrom zip zipr #' @export run_app <- function(...) { + require("dplyr") + require("DT") + require("ggplot2") + require("htmlwidgets") + require("logger") + require("PKNCA") + require("plotly") + require("reactable") + require("rio") + require("rmarkdown") + require("shinyBS") + require("shinyFiles") + require("shinyjqui") + require("shinyWidgets") + require("tools") + require("utils") + require("zip") shiny::runApp(system.file("shiny", package = "aNCA"), ...) } From 3568ffe3226409ce654ba6a079e494330da35704 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:14:21 +0000 Subject: [PATCH 04/11] fix: put csv data file in the right place --- {www => inst}/data/TLG_order_details.csv | 0 inst/shiny/modules/tab_tlg.R | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename {www => inst}/data/TLG_order_details.csv (100%) diff --git a/www/data/TLG_order_details.csv b/inst/data/TLG_order_details.csv similarity index 100% rename from www/data/TLG_order_details.csv rename to inst/data/TLG_order_details.csv diff --git a/inst/shiny/modules/tab_tlg.R b/inst/shiny/modules/tab_tlg.R index bdbf220..fc365f1 100644 --- a/inst/shiny/modules/tab_tlg.R +++ b/inst/shiny/modules/tab_tlg.R @@ -88,7 +88,7 @@ tab_tlg_server <- function(id, data) { # Make available the CSV file with the TLG list and available links to NEST tlg_order <- reactiveVal( - read.csv(system.file("www/data/TLG_order_details.csv", package = "aNCA")) %>% + read.csv(system.file("data/TLG_order_details.csv", package = "aNCA")) %>% mutate(PKid = paste0("", PKid, "")) ) From 4b2aef9437d39bae337062a3e87583a6c69b7e96 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:17:19 +0000 Subject: [PATCH 05/11] fix: require aNCA itself when running the app --- R/run_app.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/run_app.R b/R/run_app.R index 790f9ca..3f6fddf 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -5,6 +5,7 @@ #' #' @param ... Arguments passed to `shiny::runApp()` #' +#' @import aNCA #' @import shiny #' @importFrom dplyr mutate filter select group_by summarise pull arrange ungroup #' @importFrom dplyr rename_with across case_when left_join rename @@ -28,6 +29,7 @@ #' @importFrom zip zipr #' @export run_app <- function(...) { + require("aNCA") require("dplyr") require("DT") require("ggplot2") From 40cb289f5ed052996cfbaf0296b23f6eb8a1cc1d Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:28:06 +0000 Subject: [PATCH 06/11] refactor: export functions used in the app --- R/utils-slope_selector.R | 13 ++++++---- R/utils.R | 7 ++--- inst/shiny/modules/slope_selector.R | 10 ++++---- tests/testthat/test-utils-slope_selector.R | 30 +++++++++++----------- tests/testthat/test-utils.R | 16 ++++++------ 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/R/utils-slope_selector.R b/R/utils-slope_selector.R index 068cf1f..5e7d57e 100644 --- a/R/utils-slope_selector.R +++ b/R/utils-slope_selector.R @@ -12,7 +12,8 @@ #' columns modified in accordance to the provided slope filters. #' @importFrom dplyr filter group_by mutate #' -.filter_slopes <- function(data, slopes, profiles) { +#' @export +filter_slopes <- function(data, slopes, profiles) { if (is.null(data) || is.null(data$conc) || is.null(data$conc$data)) stop("Please provide valid data.") @@ -39,7 +40,7 @@ # Go over all rules and check if there is no overlap - if there is, edit accordingly slopes <- purrr::reduce( split(slopes, seq_len(nrow(slopes))), - .f = ~ .check_slope_rule_overlap(.x, .y, .keep = TRUE) + .f = ~ check_slope_rule_overlap(.x, .y, .keep = TRUE) ) } @@ -84,7 +85,9 @@ #' that the user wants to remove rule if new range already exists in the dataset. #' If TRUE, in that case full range will be kept. #' @returns Data frame with full ruleset, adjusted for new rules. -.check_slope_rule_overlap <- function(existing, new, .keep = FALSE) { +#' +#' @export +check_slope_rule_overlap <- function(existing, new, .keep = FALSE) { # check if any rule already exists for specific patient and profile # existing_index <- which( existing$TYPE == new$TYPE & @@ -106,11 +109,11 @@ if (is_diff || .keep) { existing$IXrange[existing_index] <- unique(c(existing_range, new_range)) %>% - .compress_range() + compress_range() } else if (is_inter) { existing$IXrange[existing_index] <- setdiff(existing_range, new_range) %>% - .compress_range() + compress_range() } dplyr::filter(existing, !is.na(IXrange)) diff --git a/R/utils.R b/R/utils.R index 4c61203..c831fc3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -27,11 +27,12 @@ #' @examples #' \dontrun{ #' # Basic usage -#' .compress_range(c(1, 2, 3, 4)) # "1:4" -#' .compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)) # "1:5,10:12,15" +#' compress_range(c(1, 2, 3, 4)) # "1:4" +#' compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)) # "1:5,10:12,15" #' } #' -.compress_range <- function(range_vector) { +#' @export +compress_range <- function(range_vector) { if (!is(range_vector, "numeric")) range_vector <- suppressWarnings(as.numeric(range_vector)) if (any(is.na(range_vector))) stop("Error: only numeric values allowed") if (length(range_vector) == 0) return(NA_integer_) diff --git a/inst/shiny/modules/slope_selector.R b/inst/shiny/modules/slope_selector.R index 4d09bff..8c8f9f4 100644 --- a/inst/shiny/modules/slope_selector.R +++ b/inst/shiny/modules/slope_selector.R @@ -348,12 +348,12 @@ slope_selector_server <- function( # Observe input$nca observeEvent(profiles_per_patient(), { - mydata(.filter_slopes(mydata(), manual_slopes(), profiles_per_patient())) + mydata(filter_slopes(mydata(), manual_slopes(), profiles_per_patient())) }) #' saves and implements provided ruleset observeEvent(input$save_ruleset, { - mydata(.filter_slopes(mydata(), manual_slopes(), profiles_per_patient())) + mydata(filter_slopes(mydata(), manual_slopes(), profiles_per_patient())) rv$trigger <- rv$trigger + 1 }) @@ -362,7 +362,7 @@ slope_selector_server <- function( #' and exclusions before applying them to the actual dataset. plot_data <- reactive({ req(mydata(), manual_slopes(), profiles_per_patient()) - .filter_slopes(mydata(), manual_slopes(), profiles_per_patient()) + filter_slopes(mydata(), manual_slopes(), profiles_per_patient()) }) %>% shiny::debounce(750) @@ -402,7 +402,7 @@ slope_selector_server <- function( ) # Check if there is any overlap with existing rules, adda new or edit accordingly - new_manual_slopes <- .check_slope_rule_overlap(manual_slopes(), new_slope_rule) + new_manual_slopes <- check_slope_rule_overlap(manual_slopes(), new_slope_rule) manual_slopes(new_manual_slopes) @@ -429,7 +429,7 @@ slope_selector_server <- function( select(TYPE, USUBJID, DOSNO, IX, REASON) %>% mutate(PATIENT = as.character(USUBJID), PROFILE = as.character(DOSNO)) %>% group_by(TYPE, PATIENT, PROFILE, REASON) %>% - summarise(IXrange = .compress_range(IX), .groups = "keep") %>% + summarise(IXrange = compress_range(IX), .groups = "keep") %>% select(TYPE, PATIENT, PROFILE, IXrange, REASON) %>% na.omit() diff --git a/tests/testthat/test-utils-slope_selector.R b/tests/testthat/test-utils-slope_selector.R index 0b03ccb..afb18a4 100644 --- a/tests/testthat/test-utils-slope_selector.R +++ b/tests/testthat/test-utils-slope_selector.R @@ -21,7 +21,7 @@ PROFILES_FIXTURE <- list( "4" = list(1) ) -describe(".filter_slopes", { +describe("filter_slopes", { it("should handle slope selection", { selection <- data.frame( TYPE = rep("Selection", 2), @@ -31,7 +31,7 @@ describe(".filter_slopes", { REASON = "Test selection" ) - res <- .filter_slopes(DATA_FIXTURE, selection, PROFILES_FIXTURE) + res <- filter_slopes(DATA_FIXTURE, selection, PROFILES_FIXTURE) expect_true(all(res$is.included.hl[c(1:3, 6:8)])) expect_true(all(res$REASON[c(1:3, 6:8)] == "Test selection")) }) @@ -45,19 +45,19 @@ describe(".filter_slopes", { REASON = "Test exclusion" ) - res <- .filter_slopes(DATA_FIXTURE, exclusion, PROFILES_FIXTURE) + res <- filter_slopes(DATA_FIXTURE, exclusion, PROFILES_FIXTURE) expect_true(all(res$is.excluded.hl[c(5, 6, 14, 15)])) expect_true(all(res$REASON[c(5, 6, 14, 15)] == "Test exclusion")) }) it("should throw an error for invalid data", { - expect_error(.filter_slopes(NULL, NULL, PROFILES_FIXTURE), "Please provide valid data.") - expect_error(.filter_slopes(list(), NULL, PROFILES_FIXTURE), "Please provide valid data.") + expect_error(filter_slopes(NULL, NULL, PROFILES_FIXTURE), "Please provide valid data.") + expect_error(filter_slopes(list(), NULL, PROFILES_FIXTURE), "Please provide valid data.") expect_error( - .filter_slopes(list(conc = list()), NULL, PROFILES_FIXTURE), "Please provide valid data." + filter_slopes(list(conc = list()), NULL, PROFILES_FIXTURE), "Please provide valid data." ) expect_error( - .filter_slopes(list(conc = list()), NULL, PROFILES_FIXTURE), "Please provide valid data." + filter_slopes(list(conc = list()), NULL, PROFILES_FIXTURE), "Please provide valid data." ) }) }) @@ -69,7 +69,7 @@ EXISTING_FIXTURE <- data.frame( IXrange = "3:6" ) -describe(".check_slope_rule_overlap", { +describe("check_slope_rule_overlap", { it("should add new row if no overlap is detected", { # different type # NEW <- data.frame( @@ -78,7 +78,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "1:3" ) - expect_equal(nrow(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) + expect_equal(nrow(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) # different patient # NEW <- data.frame( @@ -87,7 +87,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "1:3" ) - expect_equal(nrow(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) + expect_equal(nrow(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) # different profile # NEW <- data.frame( @@ -96,7 +96,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 2, IXrange = "1:3" ) - expect_equal(nrow(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) + expect_equal(nrow(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 2) }) it("should remove overlapping points if no new points are detected", { @@ -106,7 +106,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "4:5" ) - expect_equal(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "3,6") + expect_equal(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "3,6") NEW <- data.frame( TYPE = "Exclusion", @@ -114,7 +114,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "3:4" ) - expect_equal(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "5:6") + expect_equal(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "5:6") }) it("should add new points of partial overlap is detected", { @@ -124,7 +124,7 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "4:9" ) - expect_equal(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "3:9") + expect_equal(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)$IXrange, "3:9") }) it("should remove full row if full range of rule is removed", { @@ -134,6 +134,6 @@ describe(".check_slope_rule_overlap", { PROFILE = 1, IXrange = "3:6" ) - expect_equal(nrow(.check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 0) + expect_equal(nrow(check_slope_rule_overlap(EXISTING_FIXTURE, NEW)), 0) }) }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 81d2858..5bb8a9b 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -17,29 +17,29 @@ describe(".eval_range", { }) }) -describe(".compress_range", { +describe("compress_range", { it("compreses simple range correctly", { - expect_equal(.compress_range(c(1, 2, 3, 4)), "1:4") - expect_equal(.compress_range(c(1, 5, 10, 15)), "1,5,10,15") + expect_equal(compress_range(c(1, 2, 3, 4)), "1:4") + expect_equal(compress_range(c(1, 5, 10, 15)), "1,5,10,15") }) it("compreses range with breaks correctly", { - expect_equal(.compress_range(c(1, 2, 3, 4, 5, 10, 11, 12, 15)), "1:5,10:12,15") + expect_equal(compress_range(c(1, 2, 3, 4, 5, 10, 11, 12, 15)), "1:5,10:12,15") }) it("handles unsorted vectors correctly", { - expect_equal(.compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)), "1:5,10:12,15") + expect_equal(compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)), "1:5,10:12,15") }) it("coerces character vectors to numeric if possible", { - expect_equal(.compress_range(c("1", "2", "03")), "1:3") + expect_equal(compress_range(c("1", "2", "03")), "1:3") }) it("returns NA when empty vector is provided", { - expect_true(is.na(.compress_range(c()))) + expect_true(is.na(compress_range(c()))) }) it("throws an error if any values in the vector cannot be coerced to numeric", { - expect_error(.compress_range(c(1, 2, "A", 4)), "Error: only numeric values allowed") + expect_error(compress_range(c(1, 2, "A", 4)), "Error: only numeric values allowed") }) }) From cac90621485a41128ee9e4438d9241a8dfb58a6f Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:29:32 +0000 Subject: [PATCH 07/11] docs: devtools::document() --- NAMESPACE | 3 +++ ...ope_rule_overlap.Rd => check_slope_rule_overlap.Rd} | 6 +++--- man/{dot-compress_range.Rd => compress_range.Rd} | 10 +++++----- man/{dot-filter_slopes.Rd => filter_slopes.Rd} | 6 +++--- man/run_app.Rd | 5 ++++- 5 files changed, 18 insertions(+), 12 deletions(-) rename man/{dot-check_slope_rule_overlap.Rd => check_slope_rule_overlap.Rd} (86%) rename man/{dot-compress_range.Rd => compress_range.Rd} (76%) rename man/{dot-filter_slopes.Rd => filter_slopes.Rd} (91%) diff --git a/NAMESPACE b/NAMESPACE index 761a6e3..ce38fcc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,9 +4,12 @@ export(anonymize_pk_data) export(apply_filters) export(as_factor_preserve_label) export(calculate_summary_stats) +export(check_slope_rule_overlap) +export(compress_range) export(create_conc) export(create_dose) export(filter_breaks) +export(filter_slopes) export(flexible_violinboxplot) export(format_data) export(general_lineplot) diff --git a/man/dot-check_slope_rule_overlap.Rd b/man/check_slope_rule_overlap.Rd similarity index 86% rename from man/dot-check_slope_rule_overlap.Rd rename to man/check_slope_rule_overlap.Rd index fc724a6..a618807 100644 --- a/man/dot-check_slope_rule_overlap.Rd +++ b/man/check_slope_rule_overlap.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-slope_selector.R -\name{.check_slope_rule_overlap} -\alias{.check_slope_rule_overlap} +\name{check_slope_rule_overlap} +\alias{check_slope_rule_overlap} \title{Check overlap between existing and new slope rulesets} \usage{ -.check_slope_rule_overlap(existing, new, .keep = FALSE) +check_slope_rule_overlap(existing, new, .keep = FALSE) } \arguments{ \item{existing}{Data frame with existing selections and exclusions.} diff --git a/man/dot-compress_range.Rd b/man/compress_range.Rd similarity index 76% rename from man/dot-compress_range.Rd rename to man/compress_range.Rd index 1ea3c16..c6b9d47 100644 --- a/man/dot-compress_range.Rd +++ b/man/compress_range.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils.R -\name{.compress_range} -\alias{.compress_range} +\name{compress_range} +\alias{compress_range} \title{Compresses a numeric vector into the simplest possible character string that, when evaluated, will create the same numeric vector.} \usage{ -.compress_range(range_vector) +compress_range(range_vector) } \arguments{ \item{range_vector}{numeric vector with numbers to compress into string} @@ -20,8 +20,8 @@ will create the same numeric vector. \examples{ \dontrun{ # Basic usage -.compress_range(c(1, 2, 3, 4)) # "1:4" -.compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)) # "1:5,10:12,15" +compress_range(c(1, 2, 3, 4)) # "1:4" +compress_range(c(15, 1, 11, 4, 5, 10, 2, 12, 3)) # "1:5,10:12,15" } } diff --git a/man/dot-filter_slopes.Rd b/man/filter_slopes.Rd similarity index 91% rename from man/dot-filter_slopes.Rd rename to man/filter_slopes.Rd index 536763c..340a8ce 100644 --- a/man/dot-filter_slopes.Rd +++ b/man/filter_slopes.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-slope_selector.R -\name{.filter_slopes} -\alias{.filter_slopes} +\name{filter_slopes} +\alias{filter_slopes} \title{Filter dataset based on slope selections and exclusions} \usage{ -.filter_slopes(data, slopes, profiles) +filter_slopes(data, slopes, profiles) } \arguments{ \item{data}{Data to filter. Must be \code{PKNCAdata} list, containing the \code{conc} element with diff --git a/man/run_app.Rd b/man/run_app.Rd index ac183c0..3fc491b 100644 --- a/man/run_app.Rd +++ b/man/run_app.Rd @@ -4,7 +4,10 @@ \alias{run_app} \title{Run the Shiny app} \usage{ -run_app() +run_app(...) +} +\arguments{ +\item{...}{Arguments passed to \code{shiny::runApp()}} } \description{ List of functions imported for the shiny application. From bccd3bf12b6839de853c6eb0eef1635d163efa30 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:31:04 +0000 Subject: [PATCH 08/11] fix: import reactable.extras --- R/run_app.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/run_app.R b/R/run_app.R index 3f6fddf..c3b5515 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -38,6 +38,7 @@ run_app <- function(...) { require("PKNCA") require("plotly") require("reactable") + require("reactable.extras") require("rio") require("rmarkdown") require("shinyBS") From eac86681fccf691f8da28bb7b241bef492beaae5 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 11:53:02 +0000 Subject: [PATCH 09/11] chore: require all packages listed in the NAMESPACE --- R/run_app.R | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/R/run_app.R b/R/run_app.R index c3b5515..40dfff3 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -1,50 +1,38 @@ #' Run the Shiny app +#' Please do not add import roxygen comments here. This function +#' should require every namespace that is documented in the NAMESPACE. #' -#' List of functions imported for the shiny application. -#' When adding new imports, please keep the alphabetical order, at lest for packages. +#' Apart from the dependencies, this function should also load the package +#' itself, in case it is run via `aNCA::run_app()`. #' #' @param ... Arguments passed to `shiny::runApp()` #' -#' @import aNCA -#' @import shiny -#' @importFrom dplyr mutate filter select group_by summarise pull arrange ungroup -#' @importFrom dplyr rename_with across case_when left_join rename -#' @importFrom DT DTOutput renderDataTable datatable formatStyle styleEqual -#' @importFrom ggplot2 ggplot geom_errorbar geom_point geom_line labs aes facet_wrap -#' @importFrom htmlwidgets JS -#' @importFrom logger log_trace log_debug log_info log_warn log_error log_fatal -#' @importFrom PKNCA PKNCAconc PKNCAdose PKNCAdata pk.nca PKNCA.options pknca_units_table -#' @importFrom plotly plotlyOutput renderPlotly plotly_build event_data -#' @importFrom reactable reactable reactableOutput renderReactable colDef reactableTheme -#' @importFrom reactable getReactableState -#' @importFrom reactable.extras text_extra dropdown_extra -#' @importFrom rio export_list -#' @importFrom rmarkdown render -#' @importFrom shinyBS bsModal -#' @importFrom shinyFiles shinyDirChoose -#' @importFrom shinyjqui orderInput updateOrderInput -#' @importFrom shinyWidgets dropdown pickerInput switchInput updatePickerInput -#' @importFrom tools file_ext -#' @importFrom utils read.csv write.csv -#' @importFrom zip zipr #' @export run_app <- function(...) { require("aNCA") require("dplyr") require("DT") + require("forcats") require("ggplot2") + require("grid") + require("haven") require("htmlwidgets") require("logger") + require("nestcolor") require("PKNCA") require("plotly") - require("reactable") require("reactable.extras") + require("reactable") require("rio") require("rmarkdown") + require("shiny") require("shinyBS") require("shinyFiles") require("shinyjqui") require("shinyWidgets") + require("stats") + require("tern") + require("tidyr") require("tools") require("utils") require("zip") From f6c101512885a7f0637e09e50eaa2022b8de06e8 Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 12:10:38 +0000 Subject: [PATCH 10/11] chore: go back to declaring imports --- NAMESPACE | 1 + R/run_app.R | 28 +++++++++++++++++++++++----- man/run_app.Rd | 8 +++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index ce38fcc..64daf20 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,6 +74,7 @@ importFrom(logger,log_info) importFrom(logger,log_trace) importFrom(logger,log_warn) importFrom(plotly,event_data) +importFrom(plotly,ggplotly) importFrom(plotly,plotlyOutput) importFrom(plotly,plotly_build) importFrom(plotly,renderPlotly) diff --git a/R/run_app.R b/R/run_app.R index 40dfff3..ebc57c4 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -1,12 +1,30 @@ #' Run the Shiny app -#' Please do not add import roxygen comments here. This function -#' should require every namespace that is documented in the NAMESPACE. -#' -#' Apart from the dependencies, this function should also load the package -#' itself, in case it is run via `aNCA::run_app()`. #' #' @param ... Arguments passed to `shiny::runApp()` #' +#' List of packages imported for the shiny application. +#' When adding new imports, please keep the alphabetical order, at lest for packages. +#' @import shiny +#' @importFrom dplyr mutate filter select group_by summarise pull arrange ungroup +#' @importFrom dplyr rename_with across case_when left_join rename +#' @importFrom DT DTOutput renderDataTable datatable formatStyle styleEqual +#' @importFrom ggplot2 ggplot geom_errorbar geom_point geom_line labs aes facet_wrap +#' @importFrom htmlwidgets JS +#' @importFrom PKNCA PKNCAconc PKNCAdose PKNCAdata pk.nca PKNCA.options pknca_units_table +#' @importFrom plotly plotlyOutput renderPlotly plotly_build event_data ggplotly +#' @importFrom reactable reactable reactableOutput renderReactable colDef reactableTheme +#' @importFrom reactable getReactableState +#' @importFrom reactable.extras text_extra dropdown_extra +#' @importFrom rio export_list +#' @importFrom rmarkdown render +#' @importFrom shinyBS bsModal +#' @importFrom shinyFiles shinyDirChoose +#' @importFrom shinyjqui orderInput updateOrderInput +#' @importFrom shinyWidgets dropdown pickerInput switchInput updatePickerInput +#' @importFrom tools file_ext +#' @importFrom utils read.csv write.csv +#' @importFrom zip zipr +#' #' @export run_app <- function(...) { require("aNCA") diff --git a/man/run_app.Rd b/man/run_app.Rd index 3fc491b..988721b 100644 --- a/man/run_app.Rd +++ b/man/run_app.Rd @@ -7,9 +7,11 @@ run_app(...) } \arguments{ -\item{...}{Arguments passed to \code{shiny::runApp()}} +\item{...}{Arguments passed to \code{shiny::runApp()} + +List of packages imported for the shiny application. +When adding new imports, please keep the alphabetical order, at lest for packages.} } \description{ -List of functions imported for the shiny application. -When adding new imports, please keep the alphabetical order, at lest for packages. +Run the Shiny app } From 4e78b01b9a6bb5dc4465081b0c3f159d30c9b35f Mon Sep 17 00:00:00 2001 From: Pavel Demin Date: Fri, 15 Nov 2024 12:25:58 +0000 Subject: [PATCH 11/11] docs: add a comment before require --- R/run_app.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/run_app.R b/R/run_app.R index ebc57c4..aef005c 100644 --- a/R/run_app.R +++ b/R/run_app.R @@ -27,6 +27,7 @@ #' #' @export run_app <- function(...) { + # Load all packages mentioned in the NAMESPACE require("aNCA") require("dplyr") require("DT")