From e0985fdb7e1ef66c08d65a458de5ea838004ff3c Mon Sep 17 00:00:00 2001 From: Gustav Delius Date: Mon, 5 Dec 2022 22:44:18 +0000 Subject: [PATCH] Comment field now preserved by set_species_param_default(). Closes #268 --- R/species_params.R | 4 +--- tests/testthat/test-species_params.R | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/R/species_params.R b/R/species_params.R index 03bca1cc5..844977302 100644 --- a/R/species_params.R +++ b/R/species_params.R @@ -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]])) { diff --git a/tests/testthat/test-species_params.R b/tests/testthat/test-species_params.R index 7bd31bbba..a1ec1039f 100644 --- a/tests/testthat/test-species_params.R +++ b/tests/testthat/test-species_params.R @@ -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