Repository navigation
Conversation
New plot/table functions placed in their own file within R/ will automatically be run by `save_all_plots`. Users retain the ability to customize individual plots with function parameters.
This is necesarry to ensure consistent pathing when the working directory changes, particularly during tests.
- moved expected figure and table files to external vectors that are referenced by each text, so they only needed to be uppdated once when a new function is added - created test for when user specifies additional plot options - created tests for when 1+ plot functions fails due to illegal plot options being specified
Original `save_all_plots` becomes `save_all_plots_old`, and will be removed later.
|
@sbreitbart-NOAA the addition of the "extract_sis_data" tests results in a race condition with the "save_all_plots" test, due to coincident file writing and deletion to the same directory. How would you like to handle this? One way is to merge the two sets of tests, since testthat/parallel runs test files in parallel rather than functions. This feels like a bad way to fix this issue. Another way would be to this would be have each test write figures and temp file to a custom directory (e.g., I have a tested/verified version of option 2 here: https://github.com/JZahner1/stockplotr/tree/test-race-conditions |
|
@JZahner1 A few thoughts:
Thanks for putting in the work to reimagine this function! |
|
|
Sorry, I'm late to this conversation and maybe I should comment on issue #432 instead, but this PR seems to be where the discussion is most active. Here are a couple quick thoughts:
Compared to the task of creating an entirely new plotting function, the chore of adding that function to |
|
@iantaylor-NOAA yah I agree on both perspectives. Both SS3 (via r4ss) and WHAM have singular functions that generate default versions of everything, so I would guess that most users would expect that feature to exist in any new plotting software. The way I designed the function parameters was so that as few plot-specific function parameters are required as possible. The three options lists that currently exist as required parameters because of specific module names are more of an issue with the default behaviors of those specific functions (e.g., the first I definitely agree that it's not ideal to keep the few required parameters for specific functions that have strange default module behavior, but I think that's a whole separate issue to deal with. Regarding 2: I do think it would be valuable to be do something like r4ss where each plot gets a number and users can customize which plots get output by specifying a vector of numbers corresponding to each plot. |
Remove implication that SPR plots and be grouped by fleet (SPR isn't a fleet specific quantity).
verify that `dat` is a dataframe and has a reasonable set of columns before trying to generate plots.
| #' | ||
| #' Default: `TRUE` | ||
| #' | ||
| #' @param plot_recruitment_options List. List object of parameter values to pass |
There was a problem hiding this comment.
Does this also include other arguments like units? Could you provide an expanded default like list("module = "TIME_SERIES", unit_label = NULL, ...) I think this would help make things a bit more clear (at least for me so i'm thinking for the users as well)
| #' | ||
| #' Default: list(module = "TIME_SERIES") | ||
| #' | ||
| #' ... Additional list objects of parameter values to pass directly to corresponding |
There was a problem hiding this comment.
I'm not sure how this would work for a large number of functions and not get confusing so I wonder if we take it out for this one. The users can run the individual functions they want to if they want this functionality
There was a problem hiding this comment.
So, this WOULD probably get confusing if you are customizing a large number of functions. I dont think that's really the intended use of this function, but I dont see the harm in allowing the option.
There was a problem hiding this comment.
Would the option not apply to every other function that also uses the ... to inherit?
There was a problem hiding this comment.
So it would like this:
save_all_plots(
dat = example_data,
figures_tables_dir = fs::path("outputs/figures"),
plot_recruitment_options = list(
module = "TIME_SERIES",
unit_label = "Millions of Recruits" # customize unit label for recruitment plot
),
plot_spawning_biomass_options = list(
ref_line = "unfished" # customize reference line for spawning biomass plot
),
plot_abundance_at_age_options = list(
scale_amount = 1, # custom scale for abundance-at-age plot
proportional = FALSE # don't proportationalize abundaance-at-age
),
plot_spr_options = list(
ylab = "Fishing Intensity (1-SPR)/(1-SPR_ref)" # custom Y label for SPR plot
),
plot_fishing_mortality_options = list(
facet = "fleet", # facet fishing mortality plot by "fleet"
group = "fleet" # group fishing mortality plot by "fleet"
)
)where each plot/table function could have its own named list
There was a problem hiding this comment.
There's probably a better way to explain it in the documentation. I added the above as an example to roxygen.
There was a problem hiding this comment.
Okay perfect that clarifies it very well imo
| # TODO: should change this so that the plot/table functions are pulled directly | ||
| # from the stockplotr NAMESPACE, rather than based on the existecnce of an R | ||
| # file, so that multiple plotting functions can live in the same file. | ||
| all_R_files <- list.files( |
There was a problem hiding this comment.
Reminder to make this change before merge 😄
There was a problem hiding this comment.
Just remove the comment or adjust the implementation? Changing the implementation requires some additional steps to make me sure we only get true plotting functions and not helpers like plot_timeseries.
There was a problem hiding this comment.
I would say the latter so it only pulls the intended plots and figures and not helpers. We will probably be using this function to help us make the dashboard
There was a problem hiding this comment.
So just drop the TODO then? And we can worry about the implementation another time?
There was a problem hiding this comment.
No I think we should do this now
There was a problem hiding this comment.
Okay. For now, what I will do I make a list of plot/table functions that we can exclude after pulling all of the functions from the package NAMESPACE. Depending how many helper functions get created and added in the future, this may eventually become untenable, but it will work fine for now.
There was a problem hiding this comment.
I think you can delete this
| names(func_pars)[which(names(func_pars)=="figures_dir")] <- "tables_dir" | ||
| } | ||
|
|
||
| cli::cli_alert_info("Attempting to execute function: {func_name}") |
There was a problem hiding this comment.
I like the idea of this, but I think it leaves some confusing to the users. Could we change it to something indicating this is exporting, then add a warning message later such as "Failed to execute: {func_name}"?
| @@ -128,453 +39,89 @@ | |||
| #' @examples | |||
| #' \dontrun{ | |||
| #' save_all_plots(dat, | |||
There was a problem hiding this comment.
| #' save_all_plots(dat, | |
| #' save_all_plots( | |
| dat = example_data, |
There was a problem hiding this comment.
Sorry for the delayed review. I absolutely LOVE this improvement to this function. It worked as intended for me when I ran my own test and used the example. Please make the small adjustments in my comments then the only thing left to do is fix the failing tests then it's good to merge. I might be able to assign copilot to do that if you're okay with it.
Tysm!!
Schiano-NOAA
left a comment
There was a problem hiding this comment.
See above comments -- meant to comment and not approve so we know not to merge until small changes are made
|
Included sentence stating intended purpose of function, and pushing users to plot customziations with the individual plotting functions, and added complex example showing how to customize many plots at once.
|
re 2: Is this not already done? If not, could you be more specific about what you are looking for? |
plot/table functions are now pulled directly from the avilable stockplotr namespace allowing for multiple functions per R file. Heler functions (e.g., `plot_timeseries`) are manually excluded.
I'm good with a separate PR so it's more manageable |
-2. I see what you did, by adding an argument that allows all plotting functions' modules to be chosen. I haven't seen a semi-anonymous function like that implemented before. Interesting! |
|
okay. let me see what's easiest, bc I made the race-conditions branch off of this PR. Not sure how linked they are. |
…atch Sum sex-specific abundances after change to example_data.
New plotting and table functions will automatically be generated with their default parameters by
save_all_plots, without requiring manual changes to thesave_all_plotsfunction. This is accomplished by pulling a list of all available plot/table functions based on the existence of a plot_.R or table_.R file in the "R/" directory.This does require that 1) the name of a plotting function matches with the name of an R file (e.g.,
plot_spawning_biomass()-> plot_spawning_biomass.R`, and 2) there can only be one function per R file.This current implementation is sub ideal, but can potentially be improved by pulling available plot/table function directly from the stockplotr NAMESPACE (though we would need to be careful to exempt utility plotting functions (e.g.,
plot_timeseries).Users retain the ability to customize individual plots within the
save_all_plotsfunction by specifying a named list of parameters as an input parameter. For example, to customize the behavior ofplot_spawning_biomass:save_all_plots( example_data, plot_spawning_biomass_options = list( ... # Whatever custom options you want to pass directory to the underlying function ) )The
save_all_plotstest does need to be updated with the name of the output file for each new function that is added. This could possible be automated in the future as well.