From f338bac92dd78029113204f839336dac9f7b6f7a Mon Sep 17 00:00:00 2001 From: Duncan Kennedy Date: Fri, 18 Oct 2024 09:58:11 -0600 Subject: [PATCH] replaced `requireNamespace()` with `rlang::check_installed()` --- DESCRIPTION | 1 + R/plot-biomass.R | 4 ++-- R/plot-fish.R | 4 ++-- R/plot-schedule.R | 4 ++-- R/plot-sr.R | 4 ++-- R/plot-yield.R | 8 ++++---- R/report.R | 11 +++-------- 7 files changed, 16 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f8560e9..0c6c44b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,7 @@ Imports: graphics, lifecycle, purrr, + rlang, stats, tibble, tidyplus, diff --git a/R/plot-biomass.R b/R/plot-biomass.R index 58145c9..d08caa3 100644 --- a/R/plot-biomass.R +++ b/R/plot-biomass.R @@ -13,8 +13,8 @@ #' @examples #' ypr_plot_biomass(ypr_population(), color = "white") ypr_plot_biomass <- function(population, y = "Biomass", color = NULL) { - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") chk_string(y) chk_subset(y, c("Biomass", "Eggs")) diff --git a/R/plot-fish.R b/R/plot-fish.R index 238f35f..4b479f0 100644 --- a/R/plot-fish.R +++ b/R/plot-fish.R @@ -16,8 +16,8 @@ ypr_plot_fish <- function(population, x = "Age", y = "Survivors", percent = FALSE, binwidth = 1L, color = NULL) { - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") chk_string(y) chk_subset(y, c( "Survivors", "Spawners", "Caught", "Harvested", diff --git a/R/plot-schedule.R b/R/plot-schedule.R index e4d408b..2c62248 100644 --- a/R/plot-schedule.R +++ b/R/plot-schedule.R @@ -12,8 +12,8 @@ #' @examples #' ypr_plot_schedule(ypr_population()) ypr_plot_schedule <- function(population, x = "Age", y = "Length") { - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") schedule <- ypr_tabulate_schedule(object = population) diff --git a/R/plot-sr.R b/R/plot-sr.R index f9de37d..3e1a08a 100644 --- a/R/plot-sr.R +++ b/R/plot-sr.R @@ -13,8 +13,8 @@ ypr_plot_sr <- function(population, harvest = TRUE, biomass = FALSE, plot_values = TRUE) { - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") chk_number(Ly) chk_gte(Ly) diff --git a/R/plot-yield.R b/R/plot-yield.R index d8bd789..0586877 100644 --- a/R/plot-yield.R +++ b/R/plot-yield.R @@ -46,8 +46,8 @@ ypr_plot_yield.default <- function(object, ...) { chkor_vld(vld_is(object, "ypr_population"), vld_is(object, "ypr_ecotypes")) - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") chk_number(Ly) chk_gte(Ly) chk_flag(biomass) @@ -120,8 +120,8 @@ ypr_plot_yield.ypr_populations <- function(object, u = harvest, plot_values = TRUE, ...) { - if (!requireNamespace("ggplot2")) err("Package 'ggplot2' must be installed.") - if (!requireNamespace("scales")) err("Package 'scales' must be installed.") + rlang::check_installed("ggplot2") + rlang::check_installed("scales") chk_string(y) chk_subset(y, c("Yield", "Age", "Length", "Weight", "Effort", "YPUE")) chk_flag(u) diff --git a/R/report.R b/R/report.R index d54c2ef..5f579f2 100644 --- a/R/report.R +++ b/R/report.R @@ -56,7 +56,7 @@ ypr_report <- function(population, chk_string(file) chk_flag(view) chk_flag(ask) - if (!requireNamespace("usethis")) err("Package 'usethis' must be installed.") + rlang::check_installed("usethis") if (grepl("[.](R|r)md$", file)) { wrn("File extension on argument `file` is deprecated (please remove).") @@ -86,9 +86,7 @@ ypr_report <- function(population, ) if (view) { - if (!requireNamespace("rmarkdown")) { - err("Package 'rmarkdown' is required to render the report to html.") - } + rlang::check_installed("rmarkdown", reason = "to render the report to html.") file_html <- p0(.sub(file, "[.](R|r)md$", ""), ".html") if (!ask_file(file_html, ask)) { @@ -96,10 +94,7 @@ ypr_report <- function(population, } rmarkdown::render(file, output_format = "html_document", quiet = TRUE) - if (!requireNamespace("rstudioapi")) { - err("Package 'rstudioapi' is required to view the html report.") - } - + rlang::check_installed("rstudioapi", reason = "to view the html report.") rstudioapi::viewer(file_html) } invisible(readLines(file))