Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensures required packages are in Imports section #774

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
48 changes: 23 additions & 25 deletions DESCRIPTION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see changes in dependencies and I immediately think about verdepcheck. Can you please confirm that it is passing on this? If not - let's work on the deps versions.

This might need to wait for https://github.com/insightsengineering/teal.modules.general/pull/774/files#r1890465398

Original file line number Diff line number Diff line change
@@ -31,16 +31,30 @@ Depends:
teal.transform (>= 0.5.0.9015)
Copy link
Contributor Author

@averissimo averissimo Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teal requirement needs to be bumped with insightsengineering/teal#1432

Possibly to teal (>= 0.15.2.9091),

Keeping conversation open until the PR is closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approved that PR, so working on this PR can continue.

Imports:
checkmate (>= 2.1.0),
colourpicker,
dplyr (>= 1.0.5),
DT (>= 0.13),
forcats (>= 1.0.0),
generics,
ggExtra,
ggpmisc (>= 0.4.3),
ggpp,
ggrepel,
goftest,
grid,
gridExtra,
htmlwidgets,
jsonlite,
lattice (>= 0.18-4),
MASS,
rtables (>= 0.6.8),
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
lifecycle (>= 0.2.0),
scales,
shinyjs,
shinyTree (>= 0.2.8),
shinyvalidate,
shinyWidgets (>= 0.5.1),
sparkline,
stats,
stringr (>= 1.4.1),
teal.code (>= 0.5.0.9012),
@@ -54,50 +68,34 @@ Imports:
tools,
utils
Suggests:
broom (>= 0.7.10),
colourpicker,
ggExtra,
ggpmisc (>= 0.4.3),
ggpp,
ggrepel,
goftest,
gridExtra,
htmlwidgets,
jsonlite,
knitr (>= 1.42),
lattice (>= 0.18-4),
logger (>= 0.2.0),
MASS,
nestcolor (>= 0.1.0),
pkgload,
rlang (>= 1.0.0),
rmarkdown (>= 2.23),
roxy.shinylive,
rtables (>= 0.6.8),
rvest,
shinytest2,
sparkline,
testthat (>= 3.1.9),
withr (>= 2.0.0)
VignetteBuilder:
knitr,
rmarkdown
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
rstudio/shiny, insightsengineering/teal,
insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr,
rstudio/DT, tidyverse/forcats, r-lib/lifecycle, r-lib/scales,
daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate,
dreamRs/shinyWidgets, tidyverse/stringr,
rstudio/shiny, insightsengineering/teal, insightsengineering/teal.transform,
mllg/checkmate, daattali/colourpicker, tidyverse/dplyr, rstudio/DT,
tidyverse/forcats, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp,
slowkow/ggrepel, baddstats/goftest, ramnathv/htmlwidgets, jeroen/jsonlite,
deepayan/lattice, insightsengineering/rtables, r-lib/lifecycle,
r-lib/scales, daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate,
dreamRs/shinyWidgets, htmlwidgets/sparkline, tidyverse/stringr,
insightsengineering/teal.code, insightsengineering/teal.data,
insightsengineering/teal.logger, insightsengineering/teal.reporter,
insightsengineering/teal.widgets, insightsengineering/tern,
tidyverse/tibble, tidyverse/tidyr, tidymodels/broom,
daattali/colourpicker, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp,
slowkow/ggrepel, baddstats/goftest, ramnathv/htmlwidgets,
jeroen/jsonlite, yihui/knitr, daroczig/logger, deepayan/lattice,
tidyverse/tibble, tidyverse/tidyr, yihui/knitr, daroczig/logger,
insightsengineering/nestcolor, r-lib/pkgload, r-lib/rlang,
rstudio/rmarkdown, insightsengineering/roxy.shinylive,
insightsengineering/rtables, tidyverse/rvest, htmlwidgets/sparkline,
rstudio/rmarkdown, insightsengineering/roxy.shinylive, tidyverse/rvest,
rstudio/shinytest2, r-lib/testthat, r-lib/withr
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
18 changes: 4 additions & 14 deletions R/tm_g_distribution.R
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # general data example
#' data <- teal_data()
@@ -89,7 +89,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # CDISC data example
#' data <- teal_data()
@@ -154,16 +154,6 @@ tm_g_distribution <- function(label = "Distribution Module",
decorators = NULL) {
message("Initializing tm_g_distribution")

# Requires Suggested packages
extra_packages <- c("ggpmisc", "ggpp", "goftest", "MASS", "broom")
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
if (length(missing_packages) > 0L) {
stop(sprintf(
"Cannot load package(s): %s.\nInstall or restart your session.",
toString(missing_packages)
))
}

# Normalize the parameters
if (inherits(dist_var, "data_extract_spec")) dist_var <- list(dist_var)
if (inherits(strata_var, "data_extract_spec")) strata_var <- list(strata_var)
@@ -1242,7 +1232,7 @@ srv_distribution <- function(id,
expr = {
test_table_data <- ANL %>%
dplyr::select(dist_var) %>%
with(., broom::glance(do.call(test, args))) %>%
with(., generics::glance(do.call(test, args))) %>%
dplyr::mutate_if(is.numeric, round, 3)
},
env = env
@@ -1256,7 +1246,7 @@ srv_distribution <- function(id,
test_table_data <- ANL %>%
dplyr::select(dist_var, s_var, g_var) %>%
dplyr::group_by_at(dplyr::vars(dplyr::any_of(groups))) %>%
dplyr::do(tests = broom::glance(do.call(test, args))) %>%
dplyr::do(tests = generics::glance(do.call(test, args))) %>%
tidyr::unnest(tests) %>%
dplyr::mutate_if(is.numeric, round, 3)
},
14 changes: 2 additions & 12 deletions R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggExtra", quietly = TRUE) && require("colourpicker", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # general data example
#' data <- teal_data()
@@ -134,7 +134,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggExtra", quietly = TRUE) && require("colourpicker", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # CDISC data example
#' data <- teal_data()
@@ -243,16 +243,6 @@ tm_g_scatterplot <- function(label = "Scatterplot",
decorators = NULL) {
message("Initializing tm_g_scatterplot")

# Requires Suggested packages
extra_packages <- c("ggpmisc", "ggExtra", "colourpicker")
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
if (length(missing_packages) > 0L) {
stop(sprintf(
"Cannot load package(s): %s.\nInstall or restart your session.",
toString(missing_packages)
))
}

# Normalize the parameters
if (inherits(x, "data_extract_spec")) x <- list(x)
if (inherits(y, "data_extract_spec")) y <- list(y)
9 changes: 2 additions & 7 deletions R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("lattice", quietly = TRUE)
#' @examples
#' # general data example
#' data <- teal_data()
#' data <- within(data, {
@@ -118,7 +118,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("lattice", quietly = TRUE)
#' @examples
#' # CDISC data example
#' data <- teal_data()
#' data <- within(data, {
@@ -181,11 +181,6 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
decorators = NULL) {
message("Initializing tm_g_scatterplotmatrix")

# Requires Suggested packages
if (!requireNamespace("lattice", quietly = TRUE)) {
stop("Cannot load lattice - please install the package or restart your session.")
}

# Normalize the parameters
if (inherits(variables, "data_extract_spec")) variables <- list(variables)

92 changes: 47 additions & 45 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
#' @examples
#' # general example data
#' data <- teal_data()
#' data <- within(data, {
@@ -85,7 +85,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
#' @examples
#' # CDISC example data
#' data <- teal_data()
#' data <- within(data, {
@@ -121,14 +121,6 @@ tm_missing_data <- function(label = "Missing data",
decorators = NULL) {
message("Initializing tm_missing_data")

# Requires Suggested packages
if (!requireNamespace("gridExtra", quietly = TRUE)) {
stop("Cannot load gridExtra - please install the package or restart your session.")
}
if (!requireNamespace("rlang", quietly = TRUE)) {
stop("Cannot load rlang - please install the package or restart your session.")
}

# Normalize the parameters
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)

@@ -1174,6 +1166,13 @@ srv_missing_data <- function(id,
ggtheme = input$ggtheme
)

# Unlikely that `rlang` is not available, new hashing may be expensive
hashing_function <- if (requireNamespace("rlang", quietly = TRUE)) {
quote(rlang::hash)
} else {
function(x) paste(as.integer(x), collapse = "")
averissimo marked this conversation as resolved.
Show resolved Hide resolved
}

teal.code::eval_code(
common_code_q(),
substitute(
@@ -1188,41 +1187,44 @@ srv_missing_data <- function(id,
)
) %>%
teal.code::eval_code(
quote({
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
dplyr::group_by_at(parent_keys) %>%
dplyr::mutate(id = dplyr::cur_group_id()) %>%
dplyr::ungroup() %>%
dplyr::group_by_at(c(parent_keys, "id")) %>%
dplyr::summarise_all(anyNA) %>%
dplyr::ungroup()

# order subjects by decreasing number of missing and then by
# missingness pattern (defined using sha1)
order_subjects <- summary_plot_patients %>%
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
dplyr::transmute(
id = dplyr::row_number(),
number_NA = apply(., 1, sum),
sha = apply(., 1, rlang::hash)
) %>%
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
getElement(name = "id")

# order columns by decreasing percent of missing values
ordered_columns <- summary_plot_patients %>%
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
dplyr::summarise(
column = create_cols_labels(colnames(.)),
na_count = apply(., MARGIN = 2, FUN = sum),
na_percent = na_count / nrow(.) * 100
) %>%
dplyr::arrange(na_percent, dplyr::desc(column))

summary_plot_patients <- summary_plot_patients %>%
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
dplyr::mutate(col = create_cols_labels(col))
})
substitute(
expr = {
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
dplyr::group_by_at(parent_keys) %>%
dplyr::mutate(id = dplyr::cur_group_id()) %>%
dplyr::ungroup() %>%
dplyr::group_by_at(c(parent_keys, "id")) %>%
dplyr::summarise_all(anyNA) %>%
dplyr::ungroup()

# order subjects by decreasing number of missing and then by
# missingness pattern (defined using sha1)
order_subjects <- summary_plot_patients %>%
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
dplyr::transmute(
id = dplyr::row_number(),
number_NA = apply(., 1, sum),
sha = apply(., 1, hashing_function)
) %>%
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
getElement(name = "id")

# order columns by decreasing percent of missing values
ordered_columns <- summary_plot_patients %>%
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
dplyr::summarise(
column = create_cols_labels(colnames(.)),
na_count = apply(., MARGIN = 2, FUN = sum),
na_percent = na_count / nrow(.) * 100
) %>%
dplyr::arrange(na_percent, dplyr::desc(column))

summary_plot_patients <- summary_plot_patients %>%
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
dplyr::mutate(col = create_cols_labels(col))
},
env = list(hashing_function = hashing_function)
)
) %>%
teal.code::eval_code(
substitute(
9 changes: 2 additions & 7 deletions R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("rtables", quietly = TRUE)
#' @examples
#' # general data example
#' data <- teal_data()
#' data <- within(data, {
@@ -87,7 +87,7 @@
#' library(teal.modules.general)
#' interactive <- function() TRUE
#' {{ next_example }}
#' @examplesIf require("rtables", quietly = TRUE)
#' @examples
#' # CDISC data example
#' data <- teal_data()
#' data <- within(data, {
@@ -147,11 +147,6 @@ tm_t_crosstable <- function(label = "Cross Table",
decorators = NULL) {
message("Initializing tm_t_crosstable")

# Requires Suggested packages
if (!requireNamespace("rtables", quietly = TRUE)) {
stop("Cannot load rtables - please install the package or restart your session.")
}

# Normalize the parameters
if (inherits(x, "data_extract_spec")) x <- list(x)
if (inherits(y, "data_extract_spec")) y <- list(y)
16 changes: 2 additions & 14 deletions R/tm_variable_browser.R
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("sparkline", quietly = TRUE) && require("htmlwidgets", quietly = TRUE) && require("jsonlite", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # general data example
#' data <- teal_data()
@@ -55,7 +55,7 @@
#' interactive <- function() TRUE
#' {{ next_example }}
# nolint start: line_length_linter.
#' @examplesIf require("sparkline", quietly = TRUE) && require("htmlwidgets", quietly = TRUE) && require("jsonlite", quietly = TRUE)
#' @examples
# nolint end: line_length_linter.
#' # CDISC example data
#' library(sparkline)
@@ -88,17 +88,6 @@ tm_variable_browser <- function(label = "Variable Browser",
ggplot2_args = teal.widgets::ggplot2_args()) {
message("Initializing tm_variable_browser")

# Requires Suggested packages
if (!requireNamespace("sparkline", quietly = TRUE)) {
stop("Cannot load sparkline - please install the package or restart your session.")
}
if (!requireNamespace("htmlwidgets", quietly = TRUE)) {
stop("Cannot load htmlwidgets - please install the package or restart your session.")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
stop("Cannot load jsonlite - please install the package or restart your session.")
}

# Start of assertions
checkmate::assert_string(label)
checkmate::assert_character(datasets_selected)
@@ -1290,7 +1279,6 @@ create_sparklines.default <- function(arr, width = 150, ...) {
as.character(tags$code("unsupported variable type", class = "text-blue"))
}


custom_sparkline_formatter <- function(labels, counts) {
htmlwidgets::JS(
sprintf(
18 changes: 8 additions & 10 deletions man/tm_g_distribution.Rd
14 changes: 6 additions & 8 deletions man/tm_g_scatterplot.Rd
14 changes: 6 additions & 8 deletions man/tm_g_scatterplotmatrix.Rd
14 changes: 6 additions & 8 deletions man/tm_missing_data.Rd
14 changes: 6 additions & 8 deletions man/tm_t_crosstable.Rd
14 changes: 6 additions & 8 deletions man/tm_variable_browser.Rd
4 changes: 3 additions & 1 deletion tests/testthat/setup-logger.R
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
logger::log_appender(function(...) NULL, namespace = "teal.modules.general")
if (requireNamespace("logger", quietly = TRUE)) {
logger::log_appender(function(...) NULL, namespace = "teal.modules.general")
}
1 change: 1 addition & 0 deletions tests/testthat/test-examples.R
Original file line number Diff line number Diff line change
@@ -153,6 +153,7 @@ for (i in rd_files()) {
{
testthat::skip_on_cran()
skip_if_too_deep(5)
testthat::skip_if_not_installed("pkgload")
if (basename(i) %in% strict_exceptions) {
op <- options()
withr::local_options(opts_partial_match_old)