Skip to content

Commit

Permalink
Merge pull request #75 from poissonconsulting/reqName
Browse files Browse the repository at this point in the history
replaced `requireNamespace()` with `rlang::check_installed()`
  • Loading branch information
dunkenwg authored Oct 18, 2024
2 parents 7338ab1 + f338bac commit 7127cbf
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Imports:
graphics,
lifecycle,
purrr,
rlang,
stats,
tibble,
tidyplus,
Expand Down
4 changes: 2 additions & 2 deletions R/plot-biomass.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
4 changes: 2 additions & 2 deletions R/plot-fish.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions R/plot-schedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions R/plot-sr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions R/plot-yield.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 3 additions & 8 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -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).")
Expand Down Expand Up @@ -86,20 +86,15 @@ 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)) {
return(invisible(readLines(file)))
}

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))
Expand Down

0 comments on commit 7127cbf

Please sign in to comment.