Skip to content

Commit 67692e3

Browse files
averissimogithub-actions[bot]llrs-rochem7pr
authored
Ensures required packages are in Imports section (#774)
# Pull Request <!--- Replace `#nnn` with your issue link for reference. --> Fixes #518 Note on removals: - Remove `broom` as the `broom:glances` method can be replaced with `generics::glances` - According to my tests (methods are being deprecated as well) #### Changes description - Removed conditional use of packages - Removes `{broom}` dependency - Uses `rlang ` conditionally - Uses Suggested packages conditional on tests --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Lluís Revilla <[email protected]> Co-authored-by: m7pr <[email protected]>
1 parent 1fd75a0 commit 67692e3

17 files changed

+125
-172
lines changed

.github/workflows/scheduled.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
strategy: ${{ matrix.test-strategy }}
3939
additional-env-vars: |
4040
PKG_SYSREQS_DRY_RUN=true
41+
extra-deps: |
42+
MultiAssayExperiment (>= 1.32.0);SummarizedExperiment (>= 1.36.0);teal.slice (>= 0.5.1.9021)
4143
branch-cleanup:
4244
if: >
4345
github.event_name == 'schedule' || (

DESCRIPTION

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,72 +27,72 @@ Depends:
2727
ggplot2 (>= 3.4.0),
2828
R (>= 3.6),
2929
shiny (>= 1.6.0),
30-
teal (>= 0.15.2.9091),
30+
teal (>= 0.15.2.9103),
3131
teal.transform (>= 0.5.0.9015)
3232
Imports:
3333
checkmate (>= 2.1.0),
34+
colourpicker (>= 1.3.0),
3435
dplyr (>= 1.0.5),
3536
DT (>= 0.13),
3637
forcats (>= 1.0.0),
38+
generics (>= 0.1.3),
39+
ggExtra (>= 0.10.1),
40+
ggpmisc (>= 0.4.3),
41+
ggpp (>= 0.5.8-1),
42+
ggrepel (>= 0.9.6),
43+
goftest (>= 1.2-3),
3744
grid,
45+
gridExtra (>= 2.3),
46+
htmlwidgets (>= 1.6.4),
47+
jsonlite (>= 1.8.9),
48+
lattice (>= 0.18-4),
49+
MASS (>= 7.3-61),
50+
rtables (>= 0.6.8),
3851
rlistings (>= 0.2.8),
39-
scales,
40-
shinyjs,
52+
scales (>= 1.3.0),
53+
shinyjs (>= 2.1.0),
4154
shinyTree (>= 0.2.8),
42-
shinyvalidate,
55+
shinyvalidate (>= 0.1.3),
4356
shinyWidgets (>= 0.5.1),
57+
sparkline (>= 2.0),
4458
stats,
4559
stringr (>= 1.4.1),
4660
teal.code (>= 0.5.0.9012),
4761
teal.data (>= 0.6.0.9015),
4862
teal.logger (>= 0.3.0.9003),
49-
teal.reporter (>= 0.3.0),
63+
teal.reporter (>= 0.3.1.9023),
5064
teal.widgets (>= 0.4.0),
5165
tern (>= 0.9.5),
5266
tibble (>= 2.0.0),
5367
tidyr (>= 0.8.3),
5468
tools,
5569
utils
5670
Suggests:
57-
broom (>= 0.7.10),
58-
colourpicker,
59-
ggExtra,
60-
ggpmisc (>= 0.4.3),
61-
ggpp,
62-
ggrepel,
63-
goftest,
64-
gridExtra,
65-
htmlwidgets,
66-
jsonlite,
6771
knitr (>= 1.42),
68-
lattice (>= 0.18-4),
69-
lifecycle (>= 0.2.0),
7072
logger (>= 0.2.0),
71-
MASS,
7273
nestcolor (>= 0.1.0),
7374
pkgload,
7475
rlang (>= 1.0.0),
7576
rmarkdown (>= 2.23),
7677
roxy.shinylive,
77-
rtables (>= 0.6.8),
7878
rvest,
7979
shinytest2,
80-
sparkline,
80+
lifecycle (>= 0.2.0),
8181
testthat (>= 3.1.9),
8282
withr (>= 2.0.0)
8383
VignetteBuilder:
8484
knitr,
8585
rmarkdown
8686
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
87-
rstudio/shiny, insightsengineering/teal,
87+
rstudio/shiny, insightsengineering/teal, insightsengineering/teal.slice,
8888
insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr,
8989
rstudio/DT, tidyverse/forcats, r-lib/lifecycle, r-lib/scales,
9090
daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate,
9191
dreamRs/shinyWidgets, tidyverse/stringr,
9292
insightsengineering/teal.code, insightsengineering/teal.data,
9393
insightsengineering/teal.logger, insightsengineering/teal.reporter,
9494
insightsengineering/teal.widgets, insightsengineering/tern,
95-
tidyverse/tibble, tidyverse/tidyr, tidymodels/broom,
95+
tidyverse/tibble, tidyverse/tidyr,
9696
daattali/colourpicker, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp,
9797
slowkow/ggrepel, baddstats/goftest, ramnathv/htmlwidgets,
9898
jeroen/jsonlite, yihui/knitr, daroczig/logger, deepayan/lattice,

R/tm_g_distribution.R

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#' interactive <- function() TRUE
6161
#' {{ next_example }}
6262
# nolint start: line_length_linter.
63-
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
63+
#' @examples
6464
# nolint end: line_length_linter.
6565
#' # general data example
6666
#' data <- teal_data()
@@ -88,7 +88,7 @@
8888
#' interactive <- function() TRUE
8989
#' {{ next_example }}
9090
# nolint start: line_length_linter.
91-
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggpp", quietly = TRUE) && require("goftest", quietly = TRUE) && require("MASS", quietly = TRUE) && require("broom", quietly = TRUE)
91+
#' @examples
9292
# nolint end: line_length_linter.
9393
#' # CDISC data example
9494
#' data <- teal_data()
@@ -153,16 +153,6 @@ tm_g_distribution <- function(label = "Distribution Module",
153153
decorators = NULL) {
154154
message("Initializing tm_g_distribution")
155155

156-
# Requires Suggested packages
157-
extra_packages <- c("ggpmisc", "ggpp", "goftest", "MASS", "broom")
158-
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
159-
if (length(missing_packages) > 0L) {
160-
stop(sprintf(
161-
"Cannot load package(s): %s.\nInstall or restart your session.",
162-
toString(missing_packages)
163-
))
164-
}
165-
166156
# Normalize the parameters
167157
if (inherits(dist_var, "data_extract_spec")) dist_var <- list(dist_var)
168158
if (inherits(strata_var, "data_extract_spec")) strata_var <- list(strata_var)
@@ -1227,7 +1217,7 @@ srv_distribution <- function(id,
12271217
expr = {
12281218
test_table_data <- ANL %>%
12291219
dplyr::select(dist_var) %>%
1230-
with(., broom::glance(do.call(test, args))) %>%
1220+
with(., generics::glance(do.call(test, args))) %>%
12311221
dplyr::mutate_if(is.numeric, round, 3)
12321222
},
12331223
env = env
@@ -1241,7 +1231,7 @@ srv_distribution <- function(id,
12411231
test_table_data <- ANL %>%
12421232
dplyr::select(dist_var, s_var, g_var) %>%
12431233
dplyr::group_by_at(dplyr::vars(dplyr::any_of(groups))) %>%
1244-
dplyr::do(tests = broom::glance(do.call(test, args))) %>%
1234+
dplyr::do(tests = generics::glance(do.call(test, args))) %>%
12451235
tidyr::unnest(tests) %>%
12461236
dplyr::mutate_if(is.numeric, round, 3)
12471237
},

R/tm_g_scatterplot.R

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#' interactive <- function() TRUE
4545
#' {{ next_example }}
4646
# nolint start: line_length_linter.
47-
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggExtra", quietly = TRUE) && require("colourpicker", quietly = TRUE)
47+
#' @examples
4848
# nolint end: line_length_linter.
4949
#' # general data example
5050
#' data <- teal_data()
@@ -133,7 +133,7 @@
133133
#' interactive <- function() TRUE
134134
#' {{ next_example }}
135135
# nolint start: line_length_linter.
136-
#' @examplesIf require("ggpmisc", quietly = TRUE) && require("ggExtra", quietly = TRUE) && require("colourpicker", quietly = TRUE)
136+
#' @examples
137137
# nolint end: line_length_linter.
138138
#' # CDISC data example
139139
#' data <- teal_data()
@@ -242,16 +242,6 @@ tm_g_scatterplot <- function(label = "Scatterplot",
242242
decorators = NULL) {
243243
message("Initializing tm_g_scatterplot")
244244

245-
# Requires Suggested packages
246-
extra_packages <- c("ggpmisc", "ggExtra", "colourpicker")
247-
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
248-
if (length(missing_packages) > 0L) {
249-
stop(sprintf(
250-
"Cannot load package(s): %s.\nInstall or restart your session.",
251-
toString(missing_packages)
252-
))
253-
}
254-
255245
# Normalize the parameters
256246
if (inherits(x, "data_extract_spec")) x <- list(x)
257247
if (inherits(y, "data_extract_spec")) y <- list(y)

R/tm_g_scatterplotmatrix.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#' library(teal.modules.general)
3131
#' interactive <- function() TRUE
3232
#' {{ next_example }}
33-
#' @examplesIf require("lattice", quietly = TRUE)
33+
#' @examples
3434
#' # general data example
3535
#' data <- teal_data()
3636
#' data <- within(data, {
@@ -117,7 +117,7 @@
117117
#' library(teal.modules.general)
118118
#' interactive <- function() TRUE
119119
#' {{ next_example }}
120-
#' @examplesIf require("lattice", quietly = TRUE)
120+
#' @examples
121121
#' # CDISC data example
122122
#' data <- teal_data()
123123
#' data <- within(data, {
@@ -180,11 +180,6 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
180180
decorators = NULL) {
181181
message("Initializing tm_g_scatterplotmatrix")
182182

183-
# Requires Suggested packages
184-
if (!requireNamespace("lattice", quietly = TRUE)) {
185-
stop("Cannot load lattice - please install the package or restart your session.")
186-
}
187-
188183
# Normalize the parameters
189184
if (inherits(variables, "data_extract_spec")) variables <- list(variables)
190185

R/tm_missing_data.R

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#' library(teal.modules.general)
5151
#' interactive <- function() TRUE
5252
#' {{ next_example }}
53-
#' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
53+
#' @examples
5454
#' # general example data
5555
#' data <- teal_data()
5656
#' data <- within(data, {
@@ -84,7 +84,7 @@
8484
#' library(teal.modules.general)
8585
#' interactive <- function() TRUE
8686
#' {{ next_example }}
87-
#' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
87+
#' @examples
8888
#' # CDISC example data
8989
#' data <- teal_data()
9090
#' data <- within(data, {
@@ -120,14 +120,6 @@ tm_missing_data <- function(label = "Missing data",
120120
decorators = NULL) {
121121
message("Initializing tm_missing_data")
122122

123-
# Requires Suggested packages
124-
if (!requireNamespace("gridExtra", quietly = TRUE)) {
125-
stop("Cannot load gridExtra - please install the package or restart your session.")
126-
}
127-
if (!requireNamespace("rlang", quietly = TRUE)) {
128-
stop("Cannot load rlang - please install the package or restart your session.")
129-
}
130-
131123
# Normalize the parameters
132124
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
133125

@@ -1173,6 +1165,13 @@ srv_missing_data <- function(id,
11731165
ggtheme = input$ggtheme
11741166
)
11751167

1168+
# Unlikely that `rlang` is not available, new hashing may be expensive
1169+
hashing_function <- if (requireNamespace("rlang", quietly = TRUE)) {
1170+
quote(rlang::hash)
1171+
} else {
1172+
function(x) paste(as.integer(x), collapse = "")
1173+
}
1174+
11761175
teal.code::eval_code(
11771176
common_code_q(),
11781177
substitute(
@@ -1187,41 +1186,44 @@ srv_missing_data <- function(id,
11871186
)
11881187
) %>%
11891188
teal.code::eval_code(
1190-
quote({
1191-
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
1192-
dplyr::group_by_at(parent_keys) %>%
1193-
dplyr::mutate(id = dplyr::cur_group_id()) %>%
1194-
dplyr::ungroup() %>%
1195-
dplyr::group_by_at(c(parent_keys, "id")) %>%
1196-
dplyr::summarise_all(anyNA) %>%
1197-
dplyr::ungroup()
1198-
1199-
# order subjects by decreasing number of missing and then by
1200-
# missingness pattern (defined using sha1)
1201-
order_subjects <- summary_plot_patients %>%
1202-
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1203-
dplyr::transmute(
1204-
id = dplyr::row_number(),
1205-
number_NA = apply(., 1, sum),
1206-
sha = apply(., 1, rlang::hash)
1207-
) %>%
1208-
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
1209-
getElement(name = "id")
1210-
1211-
# order columns by decreasing percent of missing values
1212-
ordered_columns <- summary_plot_patients %>%
1213-
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1214-
dplyr::summarise(
1215-
column = create_cols_labels(colnames(.)),
1216-
na_count = apply(., MARGIN = 2, FUN = sum),
1217-
na_percent = na_count / nrow(.) * 100
1218-
) %>%
1219-
dplyr::arrange(na_percent, dplyr::desc(column))
1220-
1221-
summary_plot_patients <- summary_plot_patients %>%
1222-
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
1223-
dplyr::mutate(col = create_cols_labels(col))
1224-
})
1189+
substitute(
1190+
expr = {
1191+
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
1192+
dplyr::group_by_at(parent_keys) %>%
1193+
dplyr::mutate(id = dplyr::cur_group_id()) %>%
1194+
dplyr::ungroup() %>%
1195+
dplyr::group_by_at(c(parent_keys, "id")) %>%
1196+
dplyr::summarise_all(anyNA) %>%
1197+
dplyr::ungroup()
1198+
1199+
# order subjects by decreasing number of missing and then by
1200+
# missingness pattern (defined using sha1)
1201+
order_subjects <- summary_plot_patients %>%
1202+
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1203+
dplyr::transmute(
1204+
id = dplyr::row_number(),
1205+
number_NA = apply(., 1, sum),
1206+
sha = apply(., 1, hashing_function)
1207+
) %>%
1208+
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
1209+
getElement(name = "id")
1210+
1211+
# order columns by decreasing percent of missing values
1212+
ordered_columns <- summary_plot_patients %>%
1213+
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1214+
dplyr::summarise(
1215+
column = create_cols_labels(colnames(.)),
1216+
na_count = apply(., MARGIN = 2, FUN = sum),
1217+
na_percent = na_count / nrow(.) * 100
1218+
) %>%
1219+
dplyr::arrange(na_percent, dplyr::desc(column))
1220+
1221+
summary_plot_patients <- summary_plot_patients %>%
1222+
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
1223+
dplyr::mutate(col = create_cols_labels(col))
1224+
},
1225+
env = list(hashing_function = hashing_function)
1226+
)
12251227
) %>%
12261228
teal.code::eval_code(
12271229
substitute(

R/tm_t_crosstable.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#' library(teal.modules.general)
3838
#' interactive <- function() TRUE
3939
#' {{ next_example }}
40-
#' @examplesIf require("rtables", quietly = TRUE)
40+
#' @examples
4141
#' # general data example
4242
#' data <- teal_data()
4343
#' data <- within(data, {
@@ -86,7 +86,7 @@
8686
#' library(teal.modules.general)
8787
#' interactive <- function() TRUE
8888
#' {{ next_example }}
89-
#' @examplesIf require("rtables", quietly = TRUE)
89+
#' @examples
9090
#' # CDISC data example
9191
#' data <- teal_data()
9292
#' data <- within(data, {
@@ -146,11 +146,6 @@ tm_t_crosstable <- function(label = "Cross Table",
146146
decorators = NULL) {
147147
message("Initializing tm_t_crosstable")
148148

149-
# Requires Suggested packages
150-
if (!requireNamespace("rtables", quietly = TRUE)) {
151-
stop("Cannot load rtables - please install the package or restart your session.")
152-
}
153-
154149
# Normalize the parameters
155150
if (inherits(x, "data_extract_spec")) x <- list(x)
156151
if (inherits(y, "data_extract_spec")) y <- list(y)

0 commit comments

Comments
 (0)