Skip to content

Commit

Permalink
refactor+style: update for epidatr 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Nov 16, 2023
1 parent 9165bcc commit c4abb04
Show file tree
Hide file tree
Showing 12 changed files with 642 additions and 557 deletions.
31 changes: 15 additions & 16 deletions data-raw/archive_cases_dv_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ library(epiprocess)
library(data.table)
library(dplyr)

dv_subset <- covidcast(
data_source = "doctor-visits",
dv_subset <- pub_covidcast(
source = "doctor-visits",
signals = "smoothed_adj_cli",
time_type = "day",
geo_type = "state",
time_values = epirange(20200601, 20211201),
time_type = "day",
geo_values = "ca,fl,ny,tx",
time_values = epirange(20200601, 20211201),
issues = epirange(20200601, 20211201)
) %>%
fetch() %>%
select(geo_value, time_value, version = issue, percent_cli = value) %>%
# We're using compactify=FALSE here and below to avoid some testthat test
# failures on tests that were based on a non-compactified version.
as_epi_archive(compactify=FALSE)
as_epi_archive(compactify = FALSE)

case_rate_subset <- covidcast(
data_source = "jhu-csse",
case_rate_subset <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_7dav_incidence_prop",
time_type = "day",
geo_type = "state",
time_values = epirange(20200601, 20211201),
time_type = "day",
geo_values = "ca,fl,ny,tx",
time_values = epirange(20200601, 20211201),
issues = epirange(20200601, 20211201)
) %>%
fetch() %>%
select(geo_value, time_value, version = issue, case_rate_7d_av = value) %>%
as_epi_archive(compactify=FALSE)
as_epi_archive(compactify = FALSE)

archive_cases_dv_subset = epix_merge(dv_subset, case_rate_subset,
sync="locf",
compactify=FALSE)
archive_cases_dv_subset <- epix_merge(dv_subset, case_rate_subset,
sync = "locf",
compactify = FALSE
)

# If we directly store an epi_archive R6 object as data, it will store its class
# implementation there as well. To prevent mismatches between these stored
# implementations and the latest class definition, don't store them as R6
# objects; store the DT and construct the R6 object on request.
archive_cases_dv_subset_dt = archive_cases_dv_subset$DT
archive_cases_dv_subset_dt <- archive_cases_dv_subset$DT
usethis::use_data(archive_cases_dv_subset_dt, overwrite = TRUE, internal = TRUE)
9 changes: 4 additions & 5 deletions data-raw/incidence_num_outlier_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ library(epiprocess)
library(dplyr)
library(tidyr)

incidence_num_outlier_example <- covidcast(
data_source = "jhu-csse",
incidence_num_outlier_example <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_incidence_num",
time_type = "day",
geo_type = "state",
time_values = epirange(20200601, 20210531),
time_type = "day",
geo_values = "fl,nj",
time_values = epirange(20200601, 20210531),
as_of = 20211028
) %>%
fetch() %>%
select(geo_value, time_value, cases = value) %>%
as_epi_df()

Expand Down
9 changes: 4 additions & 5 deletions data-raw/jhu_csse_county_level_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ y <- covidcast::county_census %>%
select(geo_value = FIPS, county_name = CTYNAME, state_name = STNAME)

# Fetch only counties from Massachusetts and Vermont, then append names columns as well
jhu_csse_county_level_subset <- covidcast(
data_source = "jhu-csse",
jhu_csse_county_level_subset <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_incidence_num",
time_type = "day",
geo_type = "county",
time_type = "day",
geo_values = paste(y$geo_value, collapse = ","),
time_values = epirange(20200601, 20211231),
geo_values = paste(y$geo_value, collapse = ",")
) %>%
fetch() %>%
select(geo_value, time_value, cases = value) %>%
full_join(y, by = "geo_value") %>%
as_epi_df()
Expand Down
59 changes: 29 additions & 30 deletions data-raw/jhu_csse_daily_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,60 @@ library(epidatr)
library(epiprocess)
library(dplyr)

confirmed_7dav_incidence_prop <- covidcast(
data_source = "jhu-csse",
confirmed_7dav_incidence_prop <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_7dav_incidence_prop",
time_type = "day",
geo_type = "state",
time_type = "day",
geo_values = "ca,fl,ny,tx,ga,pa",
time_values = epirange(20200301, 20211231),
geo_values = "ca,fl,ny,tx,ga,pa"
) %>%
fetch() %>%
select(geo_value, time_value, case_rate_7d_av = value) %>%
arrange(geo_value, time_value)
arrange(geo_value, time_value)

deaths_7dav_incidence_prop <- covidcast(
data_source = "jhu-csse",
deaths_7dav_incidence_prop <- pub_covidcast(
source = "jhu-csse",
signals = "deaths_7dav_incidence_prop",
time_type = "day",
geo_type = "state",
time_type = "day",
geo_values = "ca,fl,ny,tx,ga,pa",
time_values = epirange(20200301, 20211231),
geo_values = "ca,fl,ny,tx,ga,pa"
) %>%
fetch() %>%
select(geo_value, time_value, death_rate_7d_av = value) %>%
arrange(geo_value, time_value)
arrange(geo_value, time_value)

confirmed_incidence_num <- covidcast(
data_source = "jhu-csse",
confirmed_incidence_num <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_incidence_num",
time_type = "day",
geo_type = "state",
time_type = "day",
geo_values = "ca,fl,ny,tx,ga,pa",
time_values = epirange(20200301, 20211231),
geo_values = "ca,fl,ny,tx,ga,pa"
) %>%
fetch() %>%
select(geo_value, time_value, cases = value) %>%
arrange(geo_value, time_value)
arrange(geo_value, time_value)

confirmed_7dav_incidence_num <- covidcast(
data_source = "jhu-csse",
confirmed_7dav_incidence_num <- pub_covidcast(
source = "jhu-csse",
signals = "confirmed_7dav_incidence_num",
time_type = "day",
geo_type = "state",
time_type = "day",
geo_values = "ca,fl,ny,tx,ga,pa",
time_values = epirange(20200301, 20211231),
geo_values = "ca,fl,ny,tx,ga,pa"
) %>%
fetch() %>%
select(geo_value, time_value, cases_7d_av = value) %>%
arrange(geo_value, time_value)

jhu_csse_daily_subset <- confirmed_7dav_incidence_prop %>%
full_join(deaths_7dav_incidence_prop,
by = c("geo_value", "time_value")) %>%
full_join(confirmed_incidence_num,
by = c("geo_value", "time_value")) %>%
full_join(confirmed_7dav_incidence_num,
by = c("geo_value", "time_value")) %>%
as_epi_df()
full_join(deaths_7dav_incidence_prop,
by = c("geo_value", "time_value")
) %>%
full_join(confirmed_incidence_num,
by = c("geo_value", "time_value")
) %>%
full_join(confirmed_7dav_incidence_num,
by = c("geo_value", "time_value")
) %>%
as_epi_df()

usethis::use_data(jhu_csse_daily_subset, overwrite = TRUE)
Loading

0 comments on commit c4abb04

Please sign in to comment.