From c7290bbf239b7a170768d41a859d856eb39181c3 Mon Sep 17 00:00:00 2001 From: sbreitbart-NOAA Date: Tue, 27 Oct 2026 09:08:25 -0400 Subject: [PATCH] Remove global environment objects as per https://github.com/nmfs-ost/stockplotr/issues/421 --- R/extract_sis_data.R | 4 ++++ R/plot_biomass.R | 5 +++++ R/plot_fishing_mortality.R | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/extract_sis_data.R b/R/extract_sis_data.R index 9176af07..16a7f291 100644 --- a/R/extract_sis_data.R +++ b/R/extract_sis_data.R @@ -394,4 +394,8 @@ extract_sis_data <- function(sis_data_dir = getwd(), write.csv(ts_dat_filled, ts_dat_path, row.names = FALSE) cli::cli_alert_success("Files saved successfully in {sis_data_dir}.") } + + # remove global variables + c("biomass", "spawning_biomass", "recruitment", "fishing_mortality", "index", "catch") |> + purrr::walk(~ if (exists(.x, envir = .GlobalEnv)) rm(list = .x, envir = .GlobalEnv)) } diff --git a/R/plot_biomass.R b/R/plot_biomass.R index 724649ed..0045c54c 100644 --- a/R/plot_biomass.R +++ b/R/plot_biomass.R @@ -325,6 +325,11 @@ plot_biomass <- function( scale_amount = scale_amount ) } + + # remove global variable "selected_module" + if (exists("selected_module", envir = .GlobalEnv)) rm("selected_module", envir = .GlobalEnv) + # Output final plot final + } diff --git a/R/plot_fishing_mortality.R b/R/plot_fishing_mortality.R index bf67a4e2..deabfb69 100644 --- a/R/plot_fishing_mortality.R +++ b/R/plot_fishing_mortality.R @@ -198,6 +198,11 @@ plot_fishing_mortality <- function( scale_amount = 1 ) } + + # remove global variable "selected_module" + if (exists("selected_module", envir = .GlobalEnv)) rm("selected_module", envir = .GlobalEnv) + # Output final plot - final + final + }