Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in set_forecast_unit #427

Closed
elray1 opened this issue Nov 14, 2023 · 3 comments · Fixed by #437 or #487
Closed

error in set_forecast_unit #427

elray1 opened this issue Nov 14, 2023 · 3 comments · Fixed by #437 or #487

Comments

@elray1
Copy link
Collaborator

elray1 commented Nov 14, 2023

When attempting to call set_forecast_unit, I get an error. Here's an illustration with a small subset of the data that I'm working with:

temp <- structure(list(model = c("CADPH-FluCAT_Ensemble", "CADPH-FluCAT_Ensemble", 
"CADPH-FluCAT_Ensemble", "CADPH-FluCAT_Ensemble", "CADPH-FluCAT_Ensemble", 
"CADPH-FluCAT_Ensemble"), reference_date = structure(c(19644, 
19644, 19644, 19644, 19644, 19644), class = "Date"), target = c("wk inc flu hosp", 
"wk inc flu hosp", "wk inc flu hosp", "wk inc flu hosp", "wk inc flu hosp", 
"wk inc flu hosp"), horizon = c(0L, 0L, 0L, 0L, 0L, 0L), target_end_date = structure(c(19644, 
19644, 19644, 19644, 19644, 19644), class = "Date"), location = c("06", 
"06", "06", "06", "06", "06"), output_type = c("quantile", "quantile", 
"quantile", "quantile", "quantile", "quantile"), quantile = c("0.01", 
"0.025", "0.05", "0.1", "0.15", "0.2"), prediction = c(24.7394276619984, 
28.1962221056035, 31.1951151171218, 34.644079800571, 36.9984603087119, 
38.8655576919876), true_value = c(61, 61, 61, 61, 61, 61)), row.names = c(NA, 
-6L), class = c("model_out_tbl", "tbl_df", "tbl", "data.frame"
))

temp
> temp
# # A tibble: 6 × 10
#   model                 reference_date target          horizon target_end_date location output_type quantile prediction true_value
#   <chr>                 <date>         <chr>             <int> <date>          <chr>    <chr>       <chr>         <dbl>      <dbl>
# 1 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.01           24.7         61
# 2 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.025          28.2         61
# 3 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.05           31.2         61
# 4 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.1            34.6         61
# 5 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.15           37.0         61
# 6 CADPH-FluCAT_Ensemble 2023-10-14     wk inc flu hosp       0 2023-10-14      06       quantile    0.2            38.9         61

> scoringutils::set_forecast_unit(temp, c("model", "reference_date", "target", "horizon", "target_end_date", "location"))
Error in `[.tbl_df`(data, , .SD, .SDcols = keep_cols) : 
  object '.SD' not found

Enter a frame number, or 0 to exit   

1: scoringutils::set_forecast_unit(temp, c("model", "reference_date", "target", "horizon", "target_end_date", "location"))
2: unique(data[, .SD, .SDcols = keep_cols])
3: data[, .SD, .SDcols = keep_cols]
4: `[.tbl_df`(data, , .SD, .SDcols = keep_cols)

I'm working with the version of scoringutils that you get by installing from github.

@nikosbosse
Copy link
Contributor

Thanks for raising this! I solved the issue in #437 which will be live hopefully soon. A quick fix for now is to make sure the input is a data.table (i.e. call setDT(temp)

(This really stresses the point raised by @seabbs yesterday that we should test everything for compatibility between data.frame and data.table...)

@seabbs
Copy link
Contributor

seabbs commented Nov 19, 2023

Thanks for reporting @elray1!

@nikosbosse we should PR the fix into main not the Dev version so it's available to users now (as I am aware of at least one other person hitting this) and because it's unrelated to the Dev work.

@seabbs seabbs mentioned this issue Nov 20, 2023
nikosbosse added a commit that referenced this issue Nov 25, 2023
…unit

Issue #427: Fix error in `set_forecast_unit()` that occurs when input is not a data.table
@nikosbosse
Copy link
Contributor

We fixed this on main and will push a release to CRAN in the next few days. Thanks again, @elray1 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants