Skip to content

Commit e2275ab

Browse files
committed
chore: move required packages to imports
1 parent 5ac52a5 commit e2275ab

File tree

7 files changed

+64
-105
lines changed

7 files changed

+64
-105
lines changed

DESCRIPTION

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,29 @@ Depends:
3131
teal.transform (>= 0.5.0)
3232
Imports:
3333
checkmate (>= 2.1.0),
34+
colourpicker,
3435
dplyr (>= 1.0.5),
3536
DT (>= 0.13),
3637
forcats (>= 1.0.0),
38+
generics,
39+
ggExtra,
40+
ggpmisc (>= 0.4.3),
41+
ggpp,
42+
ggrepel,
43+
goftest,
3744
grid,
45+
gridExtra,
46+
htmlwidgets,
47+
jsonlite,
48+
lattice (>= 0.18-4),
49+
MASS,
50+
rtables (>= 0.6.8),
3851
scales,
3952
shinyjs,
4053
shinyTree (>= 0.2.8),
4154
shinyvalidate,
4255
shinyWidgets (>= 0.5.1),
56+
sparkline,
4357
stats,
4458
stringr (>= 1.4.1),
4559
teal.code (>= 0.5.0),
@@ -53,28 +67,14 @@ Imports:
5367
tools,
5468
utils
5569
Suggests:
56-
broom (>= 0.7.10),
57-
colourpicker,
58-
ggExtra,
59-
ggpmisc (>= 0.4.3),
60-
ggpp,
61-
ggrepel,
62-
goftest,
63-
gridExtra,
64-
htmlwidgets,
65-
jsonlite,
6670
knitr (>= 1.42),
67-
lattice (>= 0.18-4),
6871
logger (>= 0.2.0),
69-
MASS,
7072
nestcolor (>= 0.1.0),
7173
pkgload,
7274
rlang (>= 1.0.0),
7375
rmarkdown (>= 2.23),
74-
rtables (>= 0.6.8),
7576
rvest,
7677
shinytest2,
77-
sparkline,
7878
testthat (>= 3.1.9),
7979
withr (>= 2.0.0)
8080
VignetteBuilder:
@@ -88,10 +88,9 @@ Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
8888
insightsengineering/teal.data, insightsengineering/teal.logger,
8989
insightsengineering/teal.reporter, insightsengineering/teal.widgets,
9090
insightsengineering/tern, tidyverse/tibble, tidyverse/tidyr,
91-
tidymodels/broom, daattali/colourpicker, daattali/ggExtra,
92-
aphalo/ggpmisc, aphalo/ggpp, slowkow/ggrepel, baddstats/goftest,
93-
gridExtra, ramnathv/htmlwidgets, jeroen/jsonlite, yihui/knitr,
94-
daroczig/logger, deepayan/lattice, MASS,
91+
daattali/colourpicker, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp,
92+
slowkow/ggrepel, baddstats/goftest, gridExtra, ramnathv/htmlwidgets,
93+
jeroen/jsonlite, yihui/knitr, daroczig/logger, deepayan/lattice, MASS,
9594
insightsengineering/nestcolor, r-lib/rlang, rstudio/rmarkdown,
9695
insightsengineering/rtables, tidyverse/rvest, sparkline,
9796
rstudio/shinytest2, r-lib/testthat, r-lib/withr

R/tm_g_distribution.R

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,6 @@ tm_g_distribution <- function(label = "Distribution Module",
121121
post_output = NULL) {
122122
message("Initializing tm_g_distribution")
123123

124-
# Requires Suggested packages
125-
extra_packages <- c("ggpmisc", "ggpp", "goftest", "MASS", "broom")
126-
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
127-
if (length(missing_packages) > 0L) {
128-
stop(sprintf(
129-
"Cannot load package(s): %s.\nInstall or restart your session.",
130-
toString(missing_packages)
131-
))
132-
}
133-
134124
# Normalize the parameters
135125
if (inherits(dist_var, "data_extract_spec")) dist_var <- list(dist_var)
136126
if (inherits(strata_var, "data_extract_spec")) strata_var <- list(strata_var)
@@ -1176,7 +1166,7 @@ srv_distribution <- function(id,
11761166
expr = {
11771167
test_stats <- ANL %>%
11781168
dplyr::select(dist_var) %>%
1179-
with(., broom::glance(do.call(test, args))) %>%
1169+
with(., generics::glance(do.call(test, args))) %>%
11801170
dplyr::mutate_if(is.numeric, round, 3)
11811171
},
11821172
env = env
@@ -1190,7 +1180,7 @@ srv_distribution <- function(id,
11901180
test_stats <- ANL %>%
11911181
dplyr::select(dist_var, s_var, g_var) %>%
11921182
dplyr::group_by_at(dplyr::vars(dplyr::any_of(groups))) %>%
1193-
dplyr::do(tests = broom::glance(do.call(test, args))) %>%
1183+
dplyr::do(tests = generics::glance(do.call(test, args))) %>%
11941184
tidyr::unnest(tests) %>%
11951185
dplyr::mutate_if(is.numeric, round, 3)
11961186
},

R/tm_g_scatterplot.R

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,6 @@ tm_g_scatterplot <- function(label = "Scatterplot",
229229
ggplot2_args = teal.widgets::ggplot2_args()) {
230230
message("Initializing tm_g_scatterplot")
231231

232-
# Requires Suggested packages
233-
extra_packages <- c("ggpmisc", "ggExtra", "colourpicker")
234-
missing_packages <- Filter(function(x) !requireNamespace(x, quietly = TRUE), extra_packages)
235-
if (length(missing_packages) > 0L) {
236-
stop(sprintf(
237-
"Cannot load package(s): %s.\nInstall or restart your session.",
238-
toString(missing_packages)
239-
))
240-
}
241-
242232
# Normalize the parameters
243233
if (inherits(x, "data_extract_spec")) x <- list(x)
244234
if (inherits(y, "data_extract_spec")) y <- list(y)

R/tm_g_scatterplotmatrix.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix",
164164
post_output = NULL) {
165165
message("Initializing tm_g_scatterplotmatrix")
166166

167-
# Requires Suggested packages
168-
if (!requireNamespace("lattice", quietly = TRUE)) {
169-
stop("Cannot load lattice - please install the package or restart your session.")
170-
}
171-
172167
# Normalize the parameters
173168
if (inherits(variables, "data_extract_spec")) variables <- list(variables)
174169

R/tm_missing_data.R

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,6 @@ tm_missing_data <- function(label = "Missing data",
9191
post_output = NULL) {
9292
message("Initializing tm_missing_data")
9393

94-
# Requires Suggested packages
95-
if (!requireNamespace("gridExtra", quietly = TRUE)) {
96-
stop("Cannot load gridExtra - please install the package or restart your session.")
97-
}
98-
if (!requireNamespace("rlang", quietly = TRUE)) {
99-
stop("Cannot load rlang - please install the package or restart your session.")
100-
}
101-
10294
# Normalize the parameters
10395
if (inherits(ggplot2_args, "ggplot2_args")) ggplot2_args <- list(default = ggplot2_args)
10496

@@ -1135,6 +1127,13 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11351127
ggtheme = input$ggtheme
11361128
)
11371129

1130+
# Unlikely that `rlang` is not available, new hashing may be expensive
1131+
hashing_function <- if (requireNamespace("rlang", quietly = TRUE)) {
1132+
quote(rlang::hash)
1133+
} else {
1134+
function(x) paste(as.integer(x), collapse = "")
1135+
}
1136+
11381137
teal.code::eval_code(
11391138
common_code_q(),
11401139
substitute(
@@ -1149,41 +1148,44 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11491148
)
11501149
) %>%
11511150
teal.code::eval_code(
1152-
quote({
1153-
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
1154-
dplyr::group_by_at(parent_keys) %>%
1155-
dplyr::mutate(id = dplyr::cur_group_id()) %>%
1156-
dplyr::ungroup() %>%
1157-
dplyr::group_by_at(c(parent_keys, "id")) %>%
1158-
dplyr::summarise_all(anyNA) %>%
1159-
dplyr::ungroup()
1160-
1161-
# order subjects by decreasing number of missing and then by
1162-
# missingness pattern (defined using sha1)
1163-
order_subjects <- summary_plot_patients %>%
1164-
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1165-
dplyr::transmute(
1166-
id = dplyr::row_number(),
1167-
number_NA = apply(., 1, sum),
1168-
sha = apply(., 1, rlang::hash)
1169-
) %>%
1170-
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
1171-
getElement(name = "id")
1172-
1173-
# order columns by decreasing percent of missing values
1174-
ordered_columns <- summary_plot_patients %>%
1175-
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1176-
dplyr::summarise(
1177-
column = create_cols_labels(colnames(.)),
1178-
na_count = apply(., MARGIN = 2, FUN = sum),
1179-
na_percent = na_count / nrow(.) * 100
1180-
) %>%
1181-
dplyr::arrange(na_percent, dplyr::desc(column))
1182-
1183-
summary_plot_patients <- summary_plot_patients %>%
1184-
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
1185-
dplyr::mutate(col = create_cols_labels(col))
1186-
})
1151+
substitute(
1152+
expr = {
1153+
summary_plot_patients <- ANL[, c(parent_keys, analysis_vars)] %>%
1154+
dplyr::group_by_at(parent_keys) %>%
1155+
dplyr::mutate(id = dplyr::cur_group_id()) %>%
1156+
dplyr::ungroup() %>%
1157+
dplyr::group_by_at(c(parent_keys, "id")) %>%
1158+
dplyr::summarise_all(anyNA) %>%
1159+
dplyr::ungroup()
1160+
1161+
# order subjects by decreasing number of missing and then by
1162+
# missingness pattern (defined using sha1)
1163+
order_subjects <- summary_plot_patients %>%
1164+
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1165+
dplyr::transmute(
1166+
id = dplyr::row_number(),
1167+
number_NA = apply(., 1, sum),
1168+
sha = apply(., 1, hashing_function)
1169+
) %>%
1170+
dplyr::arrange(dplyr::desc(number_NA), sha) %>%
1171+
getElement(name = "id")
1172+
1173+
# order columns by decreasing percent of missing values
1174+
ordered_columns <- summary_plot_patients %>%
1175+
dplyr::select(-"id", -dplyr::all_of(parent_keys)) %>%
1176+
dplyr::summarise(
1177+
column = create_cols_labels(colnames(.)),
1178+
na_count = apply(., MARGIN = 2, FUN = sum),
1179+
na_percent = na_count / nrow(.) * 100
1180+
) %>%
1181+
dplyr::arrange(na_percent, dplyr::desc(column))
1182+
1183+
summary_plot_patients <- summary_plot_patients %>%
1184+
tidyr::gather("col", "isna", -"id", -dplyr::all_of(parent_keys)) %>%
1185+
dplyr::mutate(col = create_cols_labels(col))
1186+
},
1187+
env = list(hashing_function = hashing_function)
1188+
)
11871189
) %>%
11881190
teal.code::eval_code(
11891191
substitute(

R/tm_t_crosstable.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ tm_t_crosstable <- function(label = "Cross Table",
140140
basic_table_args = teal.widgets::basic_table_args()) {
141141
message("Initializing tm_t_crosstable")
142142

143-
# Requires Suggested packages
144-
if (!requireNamespace("rtables", quietly = TRUE)) {
145-
stop("Cannot load rtables - please install the package or restart your session.")
146-
}
147-
148143
# Normalize the parameters
149144
if (inherits(x, "data_extract_spec")) x <- list(x)
150145
if (inherits(y, "data_extract_spec")) y <- list(y)

R/tm_variable_browser.R

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,6 @@ tm_variable_browser <- function(label = "Variable Browser",
7878
ggplot2_args = teal.widgets::ggplot2_args()) {
7979
message("Initializing tm_variable_browser")
8080

81-
# Requires Suggested packages
82-
if (!requireNamespace("sparkline", quietly = TRUE)) {
83-
stop("Cannot load sparkline - please install the package or restart your session.")
84-
}
85-
if (!requireNamespace("htmlwidgets", quietly = TRUE)) {
86-
stop("Cannot load htmlwidgets - please install the package or restart your session.")
87-
}
88-
if (!requireNamespace("jsonlite", quietly = TRUE)) {
89-
stop("Cannot load jsonlite - please install the package or restart your session.")
90-
}
91-
9281
# Start of assertions
9382
checkmate::assert_string(label)
9483
checkmate::assert_character(datasets_selected)
@@ -1280,7 +1269,6 @@ create_sparklines.default <- function(arr, width = 150, ...) {
12801269
as.character(tags$code("unsupported variable type", class = "text-blue"))
12811270
}
12821271

1283-
12841272
custom_sparkline_formatter <- function(labels, counts) {
12851273
htmlwidgets::JS(
12861274
sprintf(

0 commit comments

Comments
 (0)