Skip to content

Commit

Permalink
Merge pull request #487 from epiforecasts/issue-427-fix-set-forecast-…
Browse files Browse the repository at this point in the history
…unit

Issue #427: Fix error in `set_forecast_unit()` that occurs when input is not a data.table
  • Loading branch information
nikosbosse authored Nov 25, 2023
2 parents 4c3bcea + a1bd8a9 commit 8ac4fc9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
- `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

## 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

Expand Down
2 changes: 1 addition & 1 deletion R/convenience-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

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

0 comments on commit 8ac4fc9

Please sign in to comment.