cmu-delphi / cmu-delphi/epipredict
Export/scope functions used in canned forecasters
- Dominant language
- R
- Stars
- 18
- Forks
- 13
- Avg merge
- 21d 58m
- Merged PRs (30d)
- 1
Description
Suppose we want to tweak `arx_forecaster()`. We probably can't just preprocess the inputs or postprocess the outputs; we want to modify the `epi_workflow` involved. It seems natural to want to copy-paste its implementation, maybe the `arx_fcast_workflow()` implementation, and maybe maybe the `arx_args_list()` implementation. One could potentially do without the latter two with the `epi_workflow` modification functions, but we don't use those much / at all in our own code/examples, so it might actually feel easier / more natural to do even more copy-pasting rather than use them.
One problem/friction with the above:
``` r
library(epipredict)
#> Loading required package: epiprocess
#>
#> Attaching package: 'epiprocess'
#> The following object is masked from 'package:stats':
#>
#> filter
#> Loading required package: parsnip
# copy-paste arx_forecaster:
arx_forecaster2 <- function (epi_data, outcome, predictors = outcome, trainer = parsnip::linear_reg(),
args_list = arx_args_list()) {
if (!is_regression(trainer)) {
cli::cli_abort("`trainer` must be a {.pkg parsnip} model of mode 'regression'.")
}
wf <- arx_fcast_epi_workflow(epi_data, outcome, predictors,
trainer, args_list)
wf <- generics::fit(wf, epi_data)
preds <- forecast(wf, fill_locf = TRUE, n_recent = args_list$nafill_buffer,
forecast_date = args_list$forecast_date %||% max(epi_data$time_value)) %>%
tibble::as_tibble() %>% dplyr::select(-time_value)
structure(list(predictions = preds, epi_workflow = wf, metadata = list(training = attr(epi_data,
"metadata"), forecast_created = Sys.time())), class = c("arx_fcast",
"canned_epipred"))
}
# copy-paste examples from ?arx_forecaster:
jhu <- case_death_rate_subset %>%
dplyr::filter(time_value >= as.Date("2021-12-01"))
out <- arx_forecaster2(
jhu, "death_rate",
c("case_rate", "death_rate")
)
#> Error in is_regression(trainer): could not find function "is_regression"
```
Created on 2024-06-18 with [reprex v2.0.2](https://reprex.tidyverse.org)
`is_regression` is a internal (non-exported) function from `epipredict`. There may be other internal functions involved, or imported, non-exported functions from other packages, that can cause similar issues. It may be helpful to:
- Export all currently-internal functions used by canned forecasters/workflows/argslists.
- Use `::` or re-export external functions used by canned forecaster/workflows/argslists.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.