Skip to content

[fix]: module name selection retained in environment when make_rda = T #421

Closed

Description

@Schiano-NOAA

When saving a plot as an rda package, the module_name that gets selected and retained in order to extract key quantities is saved into the environment. I think this should be removed once the function is finished. I think it should be fairly simple to run rm on the value.

Reprex:

plot_spawning_biomass(example_data, make_rda = TRUE)

This should result in an object in your environment of the selected module name.

Activity

  1. added theissue type on Oct 15, 2026
  2. JZahner1 commented on Oct 16, 2026

    @JZahner1
    Collaborator

    @Schiano-NOAA looks like this is happening because filter_data is using <<- notation when assigning the CLI choice to the selected_module variable (see L809). <<- is a global assignment operator and exports the variable to the global environment. It should be enough to just change these to regular <- assignments (assuming that there isn't some specific reason these need to be global assignments for the selection to work properly.

  3. Schiano-NOAA commented on Oct 16, 2026

    @Schiano-NOAA
    CollaboratorAuthor

    I think it was designed this way in order to not require the user to select the module again. I think it just needs a rm() at the end of the function so it doesn't stay in the environment.

    @sbreitbart-NOAA this is correct right?

  4. JZahner1 commented on Oct 16, 2026

    @JZahner1
    Collaborator

    A rm() call at the end of the function would certainly work. Is the selected_module that was exported being used by other processing functions then (e.g., process_data)? I feel like exporting a variable to the global environmental just so it can be reused by another functions isn't a great design pattern. Its easy to fix either way.

  5. Schiano-NOAA commented on Oct 16, 2026

    @Schiano-NOAA
    CollaboratorAuthor

    I think it's being used for the rda creation process. I see this being moot though once we standardize module_name across models and probably remove the interactivity altogether.

  6. sbreitbart-NOAA commented on Oct 16, 2026

    @sbreitbart-NOAA
    Collaborator

    7. I think it was designed this way in order to not require the user to select the module again. I think it just needs a rm() at the end of the function so it doesn't stay in the environment.
    @sbreitbart-NOAA this is correct right?

    Yes, that's correct. It's used as an argument in calc_kqs() (see, e.g., plot_biomass()). I found that saving it as an object to the environment was a way to save and then use what's sometimes interactive input. Adding rm(selected_module) at the end of the functions appears to be an simple way to resolve this issue.

  7. moved this from In progress to In Review in {stockplotr} FY27 Goals and Timelineon Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions