Skip to content

Commit

Permalink
- removeSpecies() now also removes species parameters that are not …
Browse files Browse the repository at this point in the history
…set for any of the remaining species.
  • Loading branch information
gustavdelius committed Oct 6, 2024
1 parent 98ced2e commit 83af628
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
maturity size is required.
- New species parameter `w_repro_max` giving the size at which a species
invests 100% of its energy into reproduction. Set to `w_max` by default.
- `removeSpecies()` now also removes species parameters that are not set for
any of the remaining species.
- `compareParams()` now also spells out differences in given species parameters.
- `getDiet()` now also includes the contribution of the external encounter rate
to the diet.
Expand Down
6 changes: 6 additions & 0 deletions R/manipulate_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ removeSpecies <- function(params, species) {
p@species_params$species, ]
p@gear_params <- validGearParams(p@gear_params, p@species_params)

# Drop species parameters with all values NA
keep <- colSums(is.na(p@species_params)) < nrow(p@species_params)
p@species_params <- p@species_params[, keep]
keep <- colSums(is.na(p@given_species_params)) < nrow(p@given_species_params)
p@given_species_params <- p@given_species_params[, keep]

# Preserve comments
for (slot in (slotNames(p))) {
comment(slot(p, slot)) <- comment(slot(params, slot))
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-manipulate_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ test_that("adding and then removing species leaves params unaltered", {
sp <- data.frame(species = c("new1", "new2"),
w_max = c(10, 100),
k_vb = c(4, 2),
test = "test",
stringsAsFactors = FALSE)
# add comments to test that they will be preserved as well
comment(params) <- "test"
Expand Down

0 comments on commit 83af628

Please sign in to comment.