-
Notifications
You must be signed in to change notification settings - Fork 12
Description
epipredict::flusight_hub_formatter()
errors if library(epipredict)
(or library(epiprocess)
or library(epidatasets)
) has not been called first. This occurs because it refers to epidatasets::state_census
as simply state_census
without first importing that name.
Calling library(epipredict)
or library(epiprocess)
loads epidatasets
as a required package, thus masking the issue.
This makes it less straightforward to use epipredict::flusight_hub_formatter()
in other R packages (example). I will make a PR with a simple fix.
Reprex
This is simply the flusight_hub_formatter()
example from the docs, but without loading epiprocess
or epipredict
via library()
. The internal abbr_to_location()
function errors because it cannot find the object name state_census
.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
weekly_deaths <- epidatasets::covid_case_death_rates %>%
filter(
time_value >= as.Date("2021-09-01"),
geo_value %in% c("ca", "ny", "dc", "ga", "vt")
) %>%
select(geo_value, time_value, death_rate) %>%
left_join(epidatasets::state_census %>% select(pop, abbr), by = c("geo_value" = "abbr")) %>%
mutate(deaths = pmax(death_rate / 1e5 * pop * 7, 0)) %>%
select(-pop, -death_rate) %>%
group_by(geo_value) %>%
epiprocess::epi_slide(~ sum(.$deaths), .window_size = 7, .new_col_name = "deaths_7dsum") %>%
ungroup() %>%
filter(weekdays(time_value) == "Saturday")
#> Registered S3 method overwritten by 'tsibble':
#> method from
#> as_tibble.grouped_df dplyr
cdc <- epipredict::cdc_baseline_forecaster(weekly_deaths, "deaths_7dsum")
#> Registered S3 method overwritten by 'epipredict':
#> method from
#> print.step_naomit recipes
epipredict::flusight_hub_formatter(cdc)
#> Error in `mutate()`:
#> ℹ In argument: `location = abbr_to_location(tolower(geo_value))`.
#> Caused by error in `abbr_to_location()`:
#> ! object 'state_census' not found
Created on 2025-09-17 with reprex v2.1.1