diff --git a/NEWS.md b/NEWS.md index 0acb4ed63..9cfda4d46 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ - `scoringutils` now depends on R 3.6. The change was made since packages `testthat` and `lifecycle`, which are used in `scoringutils` now require R 3.6. We also updated the Github action CI check to work with R 3.6 now. ## Bug fixes +- Fixes a bug with `set_forecast_unit()` where the function only workded with a data.table, but not a data.frame as an input. - The metrics table in the vignette [Details on the metrics implemented in `scoringutils`](https://epiforecasts.io/scoringutils/articles/metric-details.html) had duplicated entries. This was fixed by removing the duplicated rows. # scoringutils 1.2.1 @@ -11,9 +12,9 @@ ## Package updates - This minor update fixes a few issues related to gh actions and the vignettes displayed at epiforecasts.io/scoringutils. It - Gets rid of the preferably package in _pkgdown.yml. The theme had a toggle between light and dark theme that didn't work properly - - updates the gh pages deploy action to v4 and also cleans up files when triggered - - introduces a gh action to automatically render the Readme from Readme.Rmd - - removes links to vignettes that have been renamed + - Updates the gh pages deploy action to v4 and also cleans up files when triggered + - Introduces a gh action to automatically render the Readme from Readme.Rmd + - Removes links to vignettes that have been renamed # scoringutils 1.2.0 diff --git a/R/convenience-functions.R b/R/convenience-functions.R index f21aeefc8..41592d7d4 100644 --- a/R/convenience-functions.R +++ b/R/convenience-functions.R @@ -235,7 +235,7 @@ log_shift <- function(x, offset = 0, base = exp(1)) { #' ) set_forecast_unit <- function(data, forecast_unit) { - + data <- as.data.table(data) datacols <- colnames(data) missing <- forecast_unit[!(forecast_unit %in% datacols)] diff --git a/tests/testthat/test-convenience-functions.R b/tests/testthat/test-convenience-functions.R index ad7a40550..4fea72fa9 100644 --- a/tests/testthat/test-convenience-functions.R +++ b/tests/testthat/test-convenience-functions.R @@ -82,3 +82,20 @@ test_that("function get_forecast_unit() and set_forecast_unit() work together", expect_equal(fu_set, fu_get) }) + +test_that("set_forecast_unit() works on input that's not a data.table", { + df <- data.frame( + a = 1:2, + b = 2:3, + c = 3:4 + ) + expect_equal( + colnames(set_forecast_unit(df, c("a", "b"))), + c("a", "b") + ) + # apparently it also works on a matrix... good to know :) + expect_equal( + names(set_forecast_unit(as.matrix(df), "a")), + "a" + ) +})