Skip to content

Commit

Permalink
If an effort vector or effort array contains NA's, these are now repl…
Browse files Browse the repository at this point in the history
…aced by the default effort value. Closes #230
  • Loading branch information
gustavdelius committed Jul 15, 2022
1 parent a9e4ff2 commit 31024c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions R/project.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions R/setFishing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-setFishing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 31024c8

Please sign in to comment.