Skip to content

Commit

Permalink
fix(0.3.0.0): Fixes cli and -999 (#726)
Browse files Browse the repository at this point in the history
* Pluralism in cli was incorrect where a single integer needs to be passed
  before the {?*} to inform if it should be plural or not, instead of
  passing a vector like what was being done.
* Composition modules are initialized using the composition times the
  uncertainty, which was failing for -999 values because -999 * uncertainty
  does not equal -999 and was leading to the likelihood being evaluated.

Thanks to the scamp example for bringing these errors to our attention.
  • Loading branch information
kellijohnson-NOAA authored Jan 17, 2025
1 parent cb222ec commit eca8095
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: FIMS
Title: The Fisheries Integrated Modeling System
Version: 0.3.0.0
Version: 0.3.0.1
Authors@R: c(
person(c("Kelli", "F."), "Johnson", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-5149-451X")),
Expand Down
10 changes: 6 additions & 4 deletions R/distribution_formulas.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ check_distribution_validity <- function(args) {
bad <- names(check_present[unlist(check_present)])
abort_bullets <- c(
abort_bullets,
"x" = "{.var {bad}} {?is/are} missing from {.var args}."
"x" = "{.var {bad}} {cli::qty(length(bad))} {?is/are} missing from
{.var args}."
)
# Abort early because not all of the necessary items were in args
cli::cli_abort(abort_bullets)
Expand Down Expand Up @@ -107,14 +108,15 @@ check_distribution_validity <- function(args) {
abort_bullets <- c(
abort_bullets,
"x" = "{.var {elements_of_sd}} need to be present in sd.",
"i" = "Only {.code {names(sd)}} {?is/are} present."
"i" = "Only {.code {names(sd)}} {cli::qty(length(sd))} {?is/are} present."
)
} else {
if (!all(sd[["value"]] > 0)) {
if (!all(sd[["value"]] > 0, na.rm = TRUE)) {
abort_bullets <- c(
abort_bullets,
"x" = "Values passed to {.var sd} are out of bounds.",
"i" = "Values passed to {.var sd} {?is/are} {.code {sd[['value']]}}.",
"i" = "Values passed to {.var sd} {cli::qty(length(sd[['value']]))}
{?is/are} {.code {sd[['value']]}}.",
"i" = "All standard deviation (sd) values need to be positive."
)
}
Expand Down
32 changes: 20 additions & 12 deletions R/initialize_modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -514,12 +514,16 @@ initialize_age_comp <- function(data, fleet_name) {
# TODO: review the AgeComp interface, do we want to add
# `age_comp_data` as an argument?

module$age_comp_data <- age_comp_data * dplyr::filter(
.data = as.data.frame(data@data),
name == fleet_name,
type == "age"
) |>
dplyr::pull(uncertainty)
module$age_comp_data <- age_comp_data *
get_data(data) |>
dplyr::filter(
name == fleet_name,
type == "age"
) |>
dplyr::mutate(
valid_n = ifelse(value == -999, 1, uncertainty)
) |>
dplyr::pull(valid_n)

return(module)
}
Expand Down Expand Up @@ -558,12 +562,16 @@ initialize_length_comp <- function(data, fleet_name) {
# TODO: review the LengthComp interface, do we want to add
# `age_comp_data` as an argument?

module$length_comp_data <- length_comp_data * dplyr::filter(
.data = as.data.frame(data@data),
name == fleet_name,
type == "length"
) |>
dplyr::pull(uncertainty)
module$length_comp_data <- length_comp_data *
get_data(data) |>
dplyr::filter(
name == fleet_name,
type == "length"
) |>
dplyr::mutate(
valid_n = ifelse(value == -999, 1, uncertainty)
) |>
dplyr::pull(valid_n)

return(module)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/fimsfit.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
print(result)
Message
i FIMS model version: 0.3.0.0
i FIMS model version: 0.3.0.1
i Total run time was 10 seconds
i Number of parameters: total=1, fixed_effects=1, and random_effects=0
i Maximum gradient= NA
Expand Down

0 comments on commit eca8095

Please sign in to comment.