Skip to content

Commit

Permalink
Reduce package dependencies (#191)
Browse files Browse the repository at this point in the history
* update docs, tests

* remove assertthat, htmltools, magrittr imports

* move renv, testthat, usethis to suggests

* replace magrittr %>% with native pipe |>

* rename pasteMd to paste_md

* add CONTRIBUTING.md to .Rbuildignore

* fix cran checks on imports and no visible binding for global variables
  • Loading branch information
tiffanymtang authored Jan 1, 2025
1 parent 828d338 commit bf8b8db
Show file tree
Hide file tree
Showing 100 changed files with 1,645 additions and 1,625 deletions.
5 changes: 3 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
^pkgdown$
^LICENSE\.md$
^\.github$
^vignettes/results$
^vignettes/example-docs$
^vignettes/results/*
^vignettes/example-docs/*
^man-roxygen
^.*\.Rproj$
^\.Rproj\.user$
^CONTRIBUTING\.md$
14 changes: 4 additions & 10 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ Imports:
future.apply,
knitr,
lifecycle,
magrittr,
methods,
purrr,
R.utils,
assertthat,
usethis,
renv,
R6,
rlang,
rmarkdown,
stringr,
testthat (>= 3.1.0),
tibble,
tidyr,
tidyselect,
Expand All @@ -46,20 +40,21 @@ Imports:
Suggests:
broom,
callr,
devtools,
fontawesome,
fs,
future.callr,
ggplot2,
glmnet,
here,
htmltools,
lobstr,
MASS,
plotly,
progressr (>= 0.9.0),
ranger,
renv,
rstudioapi,
testthat (>= 3.1.0),
usethis,
vdiffr,
withr (>= 2.5.0),
ymlthis
Expand All @@ -70,7 +65,7 @@ Remotes:
Config/testthat/edition: 3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Collate:
'dgp.R'
'docs.R'
Expand All @@ -86,7 +81,6 @@ Collate:
'globals.R'
'init-dir.R'
'method.R'
'reexport-magrittr.R'
'run-tests.R'
'signals.R'
'use_templates.R'
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ S3method(fp,data.frame)
S3method(neg,data.frame)
S3method(pos,data.frame)
S3method(tp,data.frame)
export("%>%")
export(DGP)
export(Evaluator)
export(Experiment)
Expand Down Expand Up @@ -98,5 +97,4 @@ export(use_feature_selection_template)
export(use_inference_template)
export(use_prediction_template)
export(visualize_experiment)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
16 changes: 6 additions & 10 deletions R/docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ init_docs <- function(experiment, save_dir) {
if (!identical(descendants, list())) {
for (field in fields) {
obj_names <- purrr::map(descendants,
~names(.x[[paste0("get_", field, "s")]]())) %>%
purrr::reduce(c) %>%
~names(.x[[paste0("get_", field, "s")]]())) |>
purrr::reduce(c) |>
unique()
for (obj_name in obj_names) {
fname <- file.path(save_dir, "docs", paste0(field, "s"),
Expand Down Expand Up @@ -223,18 +223,14 @@ render_docs <- function(experiment, save_dir, write_rmd = FALSE,

output_format_type <- rlang::call_name(rlang::enexpr(output_format))
use_vmodern <- output_format_type == "vmodern"
if (use_vmodern) {
rlang::check_installed("htmltools",
reason = "to run `render_docs(output_format = vthemes::vmodern(), ...)`")
}

if (write_rmd) {
rlang::check_installed("ymlthis",
reason = "to run `render_docs(write_rmd = TRUE, ...)`")
yml_header <- ymlthis::yml() %>%
ymlthis::yml_title(title) %>%
ymlthis::yml_author(author) %>%
ymlthis::yml_output({{output_format}}) %>%
yml_header <- ymlthis::yml() |>
ymlthis::yml_title(title) |>
ymlthis::yml_author(author) |>
ymlthis::yml_output({{output_format}}) |>
ymlthis::yml_params(
sim_path = ymlthis::shiny_text(
label = "Path to Simulation Experiment Folder:",
Expand Down
39 changes: 22 additions & 17 deletions R/evaluator-lib-feature-selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ eval_feature_selection_err <- function(fit_results, vary_params = NULL,
estimate_col = NULL, imp_col,
group_cols = NULL, metrics = NULL,
na_rm = FALSE) {
# dummies to fix R CMD check note on no visible binding for global variable
.estimator <- NULL
.eval_result <- NULL

if (!is.null(metrics) && !inherits(metrics, "metric_set")) {
abort("Unknown metrics. metrics must be of class 'yardstick::metric_set' or NULL.")
Expand All @@ -153,7 +156,7 @@ eval_feature_selection_err <- function(fit_results, vary_params = NULL,
eval_feature_selection_err_fun <- function(data, truth_col, estimate_col,
imp_col, metrics, na_rm) {

data <- data %>%
data <- data |>
dplyr::mutate(
dplyr::across(tidyselect::all_of(c(truth_col, estimate_col)),
~factor(as.integer(as.numeric(.x) != 0), levels = 0:1))
Expand All @@ -168,8 +171,8 @@ eval_feature_selection_err <- function(fit_results, vary_params = NULL,
}

out <- metrics(data = data, truth = !!truth_col, estimate = !!estimate_col,
!!imp_col, na_rm = na_rm, event_level = "second") %>%
add_na_counts(data = data, value_col = imp_col, na_rm = na_rm) %>%
!!imp_col, na_rm = na_rm, event_level = "second") |>
add_na_counts(data = data, value_col = imp_col, na_rm = na_rm) |>
dplyr::select(-.estimator)
return(out)
}
Expand All @@ -179,7 +182,7 @@ eval_feature_selection_err <- function(fit_results, vary_params = NULL,
fun = eval_feature_selection_err_fun, nested_cols = nested_cols,
truth_col = truth_col, estimate_col = estimate_col, imp_col = imp_col,
group_cols = group_cols, fun_options = list(metrics = metrics), na_rm = na_rm
) %>%
) |>
tidyr::unnest(.eval_result)
return(eval_tib)
}
Expand All @@ -204,7 +207,7 @@ summarize_feature_selection_err <- function(fit_results, vary_params = NULL,
nested_cols = nested_cols, truth_col = truth_col,
estimate_col = estimate_col, imp_col = imp_col, group_cols = group_cols,
metrics = metrics, na_rm = na_rm
) %>%
) |>
dplyr::group_by(dplyr::across(tidyselect::any_of(group_vars)))

eval_summary <- eval_summarizer(
Expand Down Expand Up @@ -322,8 +325,8 @@ eval_feature_selection_curve <- function(fit_results, vary_params = NULL,
curve = c("ROC", "PR"),
na_rm = FALSE) {
if (is.null(nested_cols) || (truth_col %in% names(fit_results))) {
fit_results <- fit_results %>%
dplyr::rowwise() %>%
fit_results <- fit_results |>
dplyr::rowwise() |>
dplyr::mutate(
{{truth_col}} := factor(
as.integer(as.numeric(.data[[truth_col]]) != 0), levels = 1:0
Expand All @@ -332,7 +335,7 @@ eval_feature_selection_curve <- function(fit_results, vary_params = NULL,
} else {
fit_results[[nested_cols]] <- purrr::map(
fit_results[[nested_cols]],
~.x %>%
~.x |>
dplyr::mutate(
{{truth_col}} := factor(
as.integer(as.numeric(.data[[truth_col]]) != 0), levels = 1:0
Expand Down Expand Up @@ -366,7 +369,9 @@ summarize_feature_selection_curve <- function(fit_results, vary_params = NULL,
eval_id = ifelse(curve == "PR",
"precision",
"TPR")) {
curve_estimate <- NULL # to fix no visible binding for global variable error
# dummies to fix R CMD check note on no visible binding for global variable
curve_estimate <- NULL

if (curve == "PR") {
xvar <- "recall"
yvar <- "precision"
Expand All @@ -380,13 +385,13 @@ summarize_feature_selection_curve <- function(fit_results, vary_params = NULL,
fit_results = fit_results, vary_params = vary_params,
nested_cols = nested_cols, truth_col = truth_col, imp_col = imp_col,
group_cols = group_cols, curve = curve, na_rm = na_rm
) %>%
dplyr::rowwise() %>%
) |>
dplyr::rowwise() |>
dplyr::mutate(curve_estimate = list(rescale_curve(curve_estimate,
x_grid = x_grid,
xvar = xvar,
yvar = yvar))) %>%
tidyr::unnest(curve_estimate) %>%
yvar = yvar))) |>
tidyr::unnest(curve_estimate) |>
dplyr::group_by(dplyr::across(tidyselect::any_of(group_vars)))

eval_summary <- eval_summarizer(
Expand Down Expand Up @@ -471,13 +476,13 @@ eval_feature_importance <- function(fit_results, vary_params = NULL,
group_cols = NULL) {
id_vars <- c(".rep", ".dgp_name", ".method_name", vary_params)
if (!is.null(nested_cols)) {
fit_results <- fit_results %>%
fit_results <- fit_results |>
tidyr::unnest(tidyselect::all_of(nested_cols))
} else {
fit_results <- fit_results %>%
fit_results <- fit_results |>
tidyr::unnest(tidyselect::all_of(c(feature_col, imp_col, group_cols)))
}
eval_tib <- fit_results %>%
eval_tib <- fit_results |>
dplyr::select(
tidyselect::all_of(c(id_vars, feature_col, imp_col, group_cols))
)
Expand All @@ -502,7 +507,7 @@ summarize_feature_importance <- function(fit_results, vary_params = NULL,
fit_results = fit_results, vary_params = vary_params,
nested_cols = nested_cols, feature_col = feature_col, imp_col = imp_col,
group_cols = group_cols
) %>%
) |>
dplyr::group_by(dplyr::across(tidyselect::all_of(group_vars)))

eval_summary <- eval_summarizer(
Expand Down
Loading

0 comments on commit bf8b8db

Please sign in to comment.