refactor(create_default_*()): export modular setup helpers for modules#1628
refactor(create_default_*()): export modular setup helpers for modules#1628Bai-Li-NOAA wants to merge 6 commits into
Conversation
|
Copilot generated the Roxygen examples and unit tests for the modular helpers. I'll review both. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1628 +/- ##
==========================================
- Coverage 84.88% 84.87% -0.01%
==========================================
Files 105 105
Lines 9473 9303 -170
Branches 536 539 +3
==========================================
- Hits 8041 7896 -145
+ Misses 1395 1370 -25
Partials 37 37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@Bai-Li-NOAA I finished the rebase and I am working on the data/distribution side now. Looks like I will be able to use data as is because all distributional forms are currently hard coded 😮 it is just the uncertainty column that we have to pass through. So, I am going to leave them hardcoded for this PR and just remove the setup_default_data_*() functions and have them use the FIMSFrame directly in setting up the distributions within initialize_fims() because the data is already passed. This will set us up nicely for a future PR but keep this one contained. Anyway, I hope to have this for you to review tomorrow. Monday at the latest because we all know that I am a terrible estimator of time 😉, here is to trying to meet a deadline ❤️. |
d006625 to
e550499
Compare
|
@Bai-Li-NOAA I just pushed, it was passing all checks locally and I ran the R formatting stuff. We might need to add some tests back if code coverage goes down because I removed some files. |
927f8d3 to
7ac63a2
Compare
ec6dcbf to
f9fcaa4
Compare
* remove create_default_configurations() and tests * change create_default_parameters() to setup_default_parameters() * export modular setup helpers for fleet, selectivity, data distribution, recruitment, maturity, growth, and population * update docs, pkgdown content, README examples to the new setup_default_*() * replace old snapshots/tests with expanded test coverage for setup_default_* helpers * rename integration test files to clarify with-wrappers vs without-wrappers paths * move stockplotr from Suggests to Imports and align devecontainer package setup BREAKING CHANGE: * create_default_configuraitons() and create_default_parameters were removed; users should migrate to setup_default_parameters and setup_default_*() helpers.
Rebased and fixed some stuff in the diagnosticts Fixed not UTF-8 characters
f9fcaa4 to
e34f253
Compare
kellijohnson-NOAA
left a comment
There was a problem hiding this comment.
Great work @Bai-Li-NOAA this was needed and I think users will really like it. I have added a few commits like we talked about but I also have several comments. Some of them I directly suggested code that you can commit directly through this UI if you want. There are some additional things that I would like to see changed that I did not code.
| deqn | ||
| dlognorm | ||
| dmultinorm | ||
| Ddirichlet |
There was a problem hiding this comment.
| Ddirichlet |
I don't see Ddirichlet anywhere in the code base.
| #' @description | ||
| #' This function generates a tibble with default parameters needed to run a | ||
| #' FIMS model from a [FIMSFrame()] input object. The returned tibble includes | ||
| #' default initial values and estimation settings for each configured module. | ||
| #' You can modify the returned tibble before fitting a model (for example, | ||
| #' updating maturity and selectivity parameter values). | ||
| #' | ||
| #' @details | ||
| #' The function builds module-specific defaults by calling helper | ||
| #' functions for data, fleet, selectivity, recruitment, maturity, growth, and | ||
| #' population components, then combines those defaults into one tibble. |
There was a problem hiding this comment.
| #' @description | |
| #' This function generates a tibble with default parameters needed to run a | |
| #' FIMS model from a [FIMSFrame()] input object. The returned tibble includes | |
| #' default initial values and estimation settings for each configured module. | |
| #' You can modify the returned tibble before fitting a model (for example, | |
| #' updating maturity and selectivity parameter values). | |
| #' | |
| #' @details | |
| #' The function builds module-specific defaults by calling helper | |
| #' functions for data, fleet, selectivity, recruitment, maturity, growth, and | |
| #' population components, then combines those defaults into one tibble. | |
| #' @description | |
| #' Initializing a FIMS model, i.e., `initialize_fims()` requires a `FIMSFrame` | |
| #' object and a tibble of parameters. The parameter tibble can be automatically | |
| #' generated using this function or by building up your own tibble from | |
| #' helper functions used within this function. The resulting tibble will have | |
| #' all of the necessary parameters, specific to your data, to run a FIMS | |
| #' model. | |
| #' | |
| #' @details | |
| #' The function builds module-specific defaults by calling helper | |
| #' functions for data, fleet, selectivity, recruitment, maturity, growth, and | |
| #' population components, then combines those defaults into one tibble. | |
| #' You can modify the returned tibble before fitting a model (for example, | |
| #' updating maturity and selectivity parameter values). | |
| #' | |
| #' To create the default initial numbers at age, this function uses the defaults | |
| #' from `setup_default_Population()` and `setup_default_recruitment()`, which | |
| #' are passed to `setup_default_init_naa()` to calculate initial numbers at age. |
| #' "fixed_effects", "random_effects").} | ||
| #' \item{\code{distribution_type}:}{The type of distribution (e.g., "data", | ||
| #' "process"), where a process distribution can refer to a fixed effect or a | ||
| #' random effect but it does not fit to data, e.g., recruitment deviation.} |
There was a problem hiding this comment.
Is the e.g. an example of what it does pertain to or what it doesn't pertain to. The sentence is confusing as written. If you want to have examples, I think you should give examples of each.
| #' @rdname setup_default_parameters | ||
| #' @keywords setup_default_parameters | ||
| #' @seealso | ||
| #' * [FIMSFrame()] |
There was a problem hiding this comment.
| #' * [FIMSFrame()] | |
| #' * [FIMSFrame()] | |
| #' * [initialize_fims()] |
| setup_default_parameters <- function( | ||
| data | ||
| ) { |
There was a problem hiding this comment.
| setup_default_parameters <- function( | |
| data | |
| ) { | |
| setup_default_parameters <- function(data) { |
| #' @param distribution A string specifying the distribution type for the stock--recruitment | ||
| #' deviations. The default is `NA_character_`, which means that the stock--recruitment | ||
| #' deviations are not estimated. |
There was a problem hiding this comment.
We do not want the default to be stock--recruitment deviations that are not estimated. The default should be as random effects with a normal distribution.
| #' normal distribution, i.e., `DnormDistribution`, module. | ||
| #' @param value A real number that is passed to `log_sd`. The default value is | ||
| #' `0.1`. | ||
| #' @param data An S4 object. FIMS input data. |
There was a problem hiding this comment.
Same comment as others, I am going to stop commenting on this but it should be checked throughout.
| @@ -0,0 +1,83 @@ | |||
| # Internal helper: validate the expected FIMSFrame input class. | |||
| assert_is_fims_frame <- function(data) { | |||
There was a problem hiding this comment.
I think the cli comments should have been added to is.FIMSFrame() instead of creating a new function.
| assert_fleet_in_data <- function(data, fleet) { | ||
| fleets <- get_fleets(data) | ||
| if (!fleet %in% fleets) { | ||
| cli::cli_abort(c( | ||
| "i" = "{.var fleet} is not present in the {.var data}.", | ||
| "x" = "Available fleet names are: {.val {fleets}}." | ||
| )) | ||
| } | ||
| } |
There was a problem hiding this comment.
This should be in the FIMSFrame file.
| } | ||
|
|
||
| # Internal helper: check that a requested module type exists for a fleet. | ||
| assert_module_type_available <- function(data, fleet, module_type) { |
There was a problem hiding this comment.
This function is not used, also it is confusing because you are looking for a data type not a module. If this function stays, it should move to R/fimsframe.R.
What is the feature?
create_default_*()functions to users #1578 and Fixdistribution_typedefaults when recruitmentdistributionis set toNA#1588How have you implemented the solution?
Does the PR impact any other area of the project, maybe another repo?
Instructions for code reviewer
👋Hello reviewer👋, thank you for taking the time to review this PR!
nit:(for nitpicking) as the comment type. For example,nit:I prefer using adata.frame()instead of amatrixbecause ...This PR is now ready to be merged.Checklist