Skip to content

Commit

Permalink
Comment field now preserved by set_species_param_default(). Closes #268
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavdelius committed Dec 5, 2022
1 parent 1d56040 commit e0985fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 1 addition & 3 deletions R/species_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ set_species_param_default <- function(object, parname, default,
signal(message,
class = "info_about_default", var = parname, level = 3)
}
species_params <- data.frame(species_params, default,
stringsAsFactors = FALSE)
colnames(species_params)[[ncol(species_params)]] <- parname
species_params[parname] <- default
} else {
# We do not like factors
if (is.factor(species_params[[parname]])) {
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-species_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ test_that("validSpeciesParams() works", {

## set_species_param_default ----
test_that("set_species_param_default sets default correctly", {
# Add comments to test that they are preserved
comment(params@species_params) <- "top"
comment(params@species_params$w_inf) <- "test"
# creates new column correctly
expect_condition(set_species_param_default(params, "hype", 2, "hi"),
"hi", class = "info_about_default")
p2 <- set_species_param_default(params, "hype", 2, "hi")
expect_identical(p2@species_params$hype, rep(2, no_sp))
expect_identical(comment(p2@species_params$w_inf), "test")
expect_identical(comment(p2@species_params), "top")
expect_message(sp2 <- set_species_param_default(params@species_params, "hype", 3), NA)
expect_identical(sp2$hype, rep(3, no_sp))
# does not change existing colunn
Expand Down

0 comments on commit e0985fd

Please sign in to comment.