Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced requireNamespace() with rlang::check_installed() #75

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
)

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.")

Check warning on line 89 in R/report.R

View check run for this annotation

Codecov / codecov/patch

R/report.R#L89

Added line #L89 was not covered by tests

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.")

Check warning on line 97 in R/report.R

View check run for this annotation

Codecov / codecov/patch

R/report.R#L97

Added line #L97 was not covered by tests
rstudioapi::viewer(file_html)
}
invisible(readLines(file))
Expand Down
Loading