diff --git a/NEWS.md b/NEWS.md index 74f5c5413..3cfadf31c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,13 @@ # mizer (development version) * Improved defaults can now be implemented while keeping backwards compatibility - via `defaults_edition()`. + via `defaults_edition()`. #186 * New defaults edition 2: catchability = 0.3 instead of 1, initial effort = 1 - instead of 0. + instead of 0. #243 * In defaults edition 2, `get_gamma_default()` ensures a feeding level of `f0` - for larvae also if `interaction_resource` is not equal to 1. + for larvae also if `interaction_resource` is not equal to 1. #238 +* If an effort vector or effort array contains NA's, these are now replaced by + the default effort value. #230 * The entries of the interaction matrix and of interaction_resource are not longer restricted to be less or equal to 1. #232 * If user supplies no row names in the interaction matrix but give column names diff --git a/R/project.R b/R/project.R index 809942ab1..b8ad124d1 100644 --- a/R/project.R +++ b/R/project.R @@ -418,6 +418,11 @@ validEffortArray <- function(effort, params) { if (is.unsorted(time_effort)) { stop("The time dimname of the effort argument should be increasing.") } + + # Replace any NA's with default value + effort_default <- ifelse(defaults_edition() < 2, 0, 1) + effort[is.na(effort)] <- effort_default + names(dimnames(effort)) <- c("time", "gear") effort } \ No newline at end of file diff --git a/R/setFishing.R b/R/setFishing.R index 7ea5ef7cc..64f1eafe7 100644 --- a/R/setFishing.R +++ b/R/setFishing.R @@ -650,6 +650,9 @@ validEffortVector <- function(effort, params) { names(new) <- missing effort <- c(effort, new) + # Set any NAs to default + effort[is.na(effort)] <- effort_default + # Sort vector effort <- effort[gear_names] diff --git a/tests/testthat/test-setFishing.R b/tests/testthat/test-setFishing.R index caba90c09..81b71b06d 100644 --- a/tests/testthat/test-setFishing.R +++ b/tests/testthat/test-setFishing.R @@ -58,6 +58,11 @@ test_that("validEffort works", { # A scrambled vector is put in the right order ies <- ie[c(2,3,1,4)] expect_identical(validEffortVector(ies, params), ie) + # NA's are replaced by default + ie[2] <- 0 + iesn <- ie + iesn[2] <- NA + expect_identical(validEffortVector(iesn, params), ie) # A single number is converted into a constant vector ie[] <- 2 expect_identical(validEffortVector(2, params), ie)