From 7c3d049e54c75018ee4f04b63b1883fe01df66ce Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sat, 11 Apr 2020 13:03:10 -0400 Subject: [PATCH] i think full coverage --- NAMESPACE | 7 ++ R/clinical-labs.R | 24 +++++ R/mortality.R | 47 ++++++++++ R/nss-cd-reg.R | 57 ++++++++++++ R/nssp-cd.R | 43 +++++++++ R/provisional-deaths.R | 62 +++++++++++++ R/public-health-labs-national.R | 57 ++++++++++++ R/public-health-labs-regional.R | 42 +++++++++ R/utils.R | 12 ++- README.Rmd | 44 +++++++++- README.md | 176 +++++++++++++++++++++++++++++++++++-- man/clinical_labs.Rd | 17 ++++ man/has_bom.Rd | 11 --- man/mortality_surveillance_data.Rd | 17 ++++ man/nssp_er_visits_national.Rd | 17 ++++ man/nssp_er_visits_regional.Rd | 17 ++++ man/provisional_death_counts.Rd | 21 +++++ man/public_health_labs_national.Rd | 17 ++++ man/public_health_labs_regional.Rd | 17 ++++ man/sans_bom.Rd | 11 --- 20 files changed, 683 insertions(+), 33 deletions(-) create mode 100644 R/clinical-labs.R create mode 100644 R/mortality.R create mode 100644 R/nss-cd-reg.R create mode 100644 R/nssp-cd.R create mode 100644 R/provisional-deaths.R create mode 100644 R/public-health-labs-national.R create mode 100644 R/public-health-labs-regional.R create mode 100644 man/clinical_labs.Rd delete mode 100644 man/has_bom.Rd create mode 100644 man/mortality_surveillance_data.Rd create mode 100644 man/nssp_er_visits_national.Rd create mode 100644 man/nssp_er_visits_regional.Rd create mode 100644 man/provisional_death_counts.Rd create mode 100644 man/public_health_labs_national.Rd create mode 100644 man/public_health_labs_regional.Rd delete mode 100644 man/sans_bom.Rd diff --git a/NAMESPACE b/NAMESPACE index 6b75a41..608b296 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,11 +3,18 @@ export(about) export(age_groups) export(available_seasons) +export(clinical_labs) export(laboratory_confirmed_hospitalizations) export(mmwr_week) export(mmwr_week_to_date) export(mmwr_weekday) export(mmwrid_map) +export(mortality_surveillance_data) +export(nssp_er_visits_national) +export(nssp_er_visits_regional) +export(provisional_death_counts) +export(public_health_labs_national) +export(public_health_labs_regional) export(surveillance_areas) import(MMWRweek) import(httr) diff --git a/R/clinical-labs.R b/R/clinical-labs.R new file mode 100644 index 0000000..0f8e756 --- /dev/null +++ b/R/clinical-labs.R @@ -0,0 +1,24 @@ +#' Retrieve U.S. Clinical Laboratories Reporting SARS-CoV-2 Test Results to CDC +#' +#' @references +#' @return data frame +#' @export +clinical_labs <- function() { + + pg <- xml2::read_html("https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/reporting-cov2-results.html") + + clab_tbl <- rvest::html_table(pg, header = TRUE, trim = TRUE)[[1]] + colnames(clab_tbl) <- c("week", "num_labs", "tested", "tested_pos", "pct_pos") + + clab_tbl$region <- "National" + clab_tbl$source <- "Clinical Labs" + + clab_tbl$week <- clean_int(clab_tbl$week) + clab_tbl$num_labs <- clean_int(clab_tbl$num_labs) + clab_tbl$tested <- clean_int(clab_tbl$tested) + clab_tbl$tested_pos <- clean_int(clab_tbl$tested_pos) + clab_tbl$pct_pos <- clean_num(clab_tbl$pct_pos)/100 + + as_tibble(clab_tbl[!is.na(clab_tbl$week),]) + +} \ No newline at end of file diff --git a/R/mortality.R b/R/mortality.R new file mode 100644 index 0000000..2eea8af --- /dev/null +++ b/R/mortality.R @@ -0,0 +1,47 @@ +#' Retrieve NCHS Mortality Surveillance Data +#' +#' @return data frame +#' @references +#' @export +mortality_surveillance_data <- function() { + + pg <- xml2::read_html("https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nchs-data.html") + + nat_tbl <- rvest::html_nodes(pg, xpath=".//table[contains(., 'Total Deaths')]") + nat_rows <- rvest::html_nodes(nat_tbl, "tbody > tr") + + lapply(nat_rows, function(.x) { + nat_tds <- rvest::html_nodes(.x, "td") + nat_tds <- gsub(",", "", rvest::html_text(nat_tds)) + as_tibble(as.data.frame( + as.list( + set_names( + nat_tds, sprintf("X%02d", 1:length(nat_tds)) + ) + ), + stringsAsFactors = FALSE + )) + }) -> nat_rows + nat_tbl <- do.call(rbind.data.frame, nat_rows) + + cov <- set_names(nat_tbl[, 1:5], c("year", "week", "total_deaths", "deaths", "pct_deaths")) + cov$cause <- "COVID-19" + + pnu <- set_names(nat_tbl[, c(1:3, 6:7)], c("year", "week", "total_deaths", "deaths", "pct_deaths")) + pnu$cause <- "Pneumonia" + + flu <- set_names(nat_tbl[, c(1:3, 8:9)], c("year", "week", "total_deaths", "deaths", "pct_deaths")) + flu$cause <- "Influenza" + + nat_tbl <- rbind(cov, pnu, flu, stringsAsFactors = FALSE) + nat_tbl$region <- "National" + nat_tbl$source <- "NCHS" + nat_tbl$year <- clean_int(nat_tbl$year) + nat_tbl$week <- clean_int(nat_tbl$week) + nat_tbl$total_deaths <- clean_int(nat_tbl$total_deaths) + nat_tbl$deaths <- clean_int(nat_tbl$deaths) + nat_tbl$pct_deaths <- clean_num(nat_tbl$pct_deaths)/100 + + as_tibble(nat_tbl[!is.na(nat_tbl$week),]) + +} \ No newline at end of file diff --git a/R/nss-cd-reg.R b/R/nss-cd-reg.R new file mode 100644 index 0000000..ef6e48b --- /dev/null +++ b/R/nss-cd-reg.R @@ -0,0 +1,57 @@ +#' Retrieve Regional Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) +#' +#' @return data frame +#' @references +#' @export +nssp_er_visits_regional <- function() { + + xml2::read_html( + "https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html" + ) -> pg + + regions <- sprintf("Region %d", 1:10) + + lapply(regions, function(region){ + + reg_tbl <- rvest::html_nodes(pg, xpath=".//table[contains(., 'National')]") + nat_rows <- rvest::html_nodes(reg_tbl, "tbody > tr") + lapply(nat_rows, function(.x) { + nat_tds <- rvest::html_nodes(.x, "td") + nat_tds <- gsub(",", "", rvest::html_text(nat_tds)) + as_tibble(as.data.frame( + as.list( + set_names( + nat_tds, sprintf("X%02d", 1:length(nat_tds)) + ) + ), + stringsAsFactors = FALSE + )) + }) -> nat_rows + reg_tbl <- do.call(rbind.data.frame, nat_rows) + + cli <- set_names(reg_tbl[, 1:5], c("week", "num_fac", "total_ed_visits", "visits", "pct_visits")) + cli$visit_type <- "cli" + + ili <- set_names(reg_tbl[, c(1:3, 6:7)], c("week", "num_fac", "total_ed_visits", "visits", "pct_visits")) + ili$visit_type <- "ili" + + reg_tbl <- rbind(ili, cli, stringsAsFactors = FALSE) + reg_tbl$region <- region + reg_tbl$source <- "Emergency Departments" + reg_tbl$week <- as.character(clean_int(reg_tbl$week)) + reg_tbl$year <- clean_int(substr(reg_tbl$week, 1, 4)) + reg_tbl$week <- clean_int(substr(reg_tbl$week, 5, 6)) + reg_tbl$num_fac <- clean_int(reg_tbl$num_fac) + reg_tbl$visits <- clean_int(reg_tbl$visits) + reg_tbl$pct_visits <- clean_num(reg_tbl$pct_visits)/100 + + reg_tbl[!is.na(reg_tbl$week),] + + + }) -> regs + + out <- do.call(rbind.data.frame, regs) + + as_tibble(out) + +} diff --git a/R/nssp-cd.R b/R/nssp-cd.R new file mode 100644 index 0000000..6f3503a --- /dev/null +++ b/R/nssp-cd.R @@ -0,0 +1,43 @@ +#' Retrieve National Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) +#' +#' @references +#' @return data frame +#' @export +nssp_er_visits_national <- function() { + + pg <- xml2::read_html("https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html") + + nat_tbl <- rvest::html_nodes(pg, xpath=".//table[contains(., 'National')]") + nat_rows <- rvest::html_nodes(nat_tbl, "tbody > tr") + lapply(nat_rows, function(.x) { + nat_tds <- rvest::html_nodes(.x, "td") + nat_tds <- gsub(",", "", rvest::html_text(nat_tds)) + as_tibble(as.data.frame( + as.list( + set_names( + nat_tds, sprintf("X%02d", 1:length(nat_tds)) + ) + ), + stringsAsFactors = FALSE + )) + }) -> nat_rows + nat_tbl <- do.call(rbind.data.frame, nat_rows) + + cli <- set_names(nat_tbl[, 1:5], c("week", "num_fac", "total_ed_visits", "visits", "pct_visits")) + cli$visit_type <- "cli" + + ili <- set_names(nat_tbl[, c(1:3, 6:7)], c("week", "num_fac", "total_ed_visits", "visits", "pct_visits")) + ili$visit_type <- "ili" + + nat_tbl <- rbind(ili, cli, stringsAsFactors = FALSE) + nat_tbl$region <- "National" + nat_tbl$source <- "Emergency Departments" + nat_tbl$year <- clean_int(substr(nat_tbl$week, 1, 4)) + nat_tbl$week <- clean_int(substr(nat_tbl$week, 5, 6)) + nat_tbl$num_fac <- clean_int(nat_tbl$num_fac) + nat_tbl$visits <- clean_int(nat_tbl$visits) + nat_tbl$pct_visits <- clean_num(nat_tbl$pct_visits)/100 + + as_tibble(nat_tbl[!is.na(nat_tbl$week),]) + +} diff --git a/R/provisional-deaths.R b/R/provisional-deaths.R new file mode 100644 index 0000000..dfce09f --- /dev/null +++ b/R/provisional-deaths.R @@ -0,0 +1,62 @@ +#' Retrieve Provisional Death Counts for Coronavirus Disease (COVID-19) +#' +#' @note Please see the indicated reference for all the caveats and precise meanings for each field. Also, +#' this function used the JSON API () +#' @return a list with 4 named elements: `by_week`, `by_age`, `by_state`, `by_sex` +#' @references +#' @export +provisional_death_counts <- function() { + + res <- jsonlite::fromJSON("https://data.cdc.gov/resource/hc4f-j6nb.json") + res <- as_tibble(res) + + res$covid_deaths <- clean_int(res$covid_deaths) + res$total_deaths <- clean_int(res$total_deaths) + res$pneumonia_deaths <- clean_int(res$pneumonia_deaths) + res$pneumonia_and_covid_deaths <- clean_int(res$pneumonia_and_covid_deaths) + res$all_influenza_deaths_j09_j11 <- clean_int(res$all_influenza_deaths_j09_j11) + res$percent_expected_deaths <- clean_num(res$percent_expected_deaths) + + by_week <- res[res$group == "By week",] + by_age <- res[res$group == "By age",] + by_state <- res[res$group == "By state",] + by_sex <- res[res$group == "By sex",] + + by_week <- by_week[!grepl("total", tolower(by_week$indicator)),] + by_week$group <- NULL + by_week$indicator <- as.Date(by_week$indicator, "%m/%d/%Y") + colnames(by_week) <- c( + "week", "covid_deaths", "total_deaths", "percent_expected_deaths", + "pneumonia_deaths", "pneumonia_and_covid_deaths", "all_influenza_deaths_j09_j11" + ) + + by_age$group <- NULL + colnames(by_age) <- c( + "age_group", "covid_deaths", "total_deaths", "percent_expected_deaths", + "pneumonia_deaths", "pneumonia_and_covid_deaths", "all_influenza_deaths_j09_j11" + ) + by_age$age_group <- sub("–", "-", by_age$age_group, fixed=TRUE) + by_age$age_group <- sub("yea.*", "yr", by_age$age_group) + + by_state$group <- NULL + colnames(by_state) <- c( + "state", "covid_deaths", "total_deaths", "percent_expected_deaths", + "pneumonia_deaths", "pneumonia_and_covid_deaths", "all_influenza_deaths_j09_j11" + ) + by_state <- by_state[by_state$state != "Total US",] + + by_sex$group <- NULL + colnames(by_sex) <- c( + "sex", "covid_deaths", "total_deaths", "percent_expected_deaths", + "pneumonia_deaths", "pneumonia_and_covid_deaths", "all_influenza_deaths_j09_j11" + ) + by_sex <- by_sex[!grepl("Total", by_sex$sex),] + + list( + by_week = as_tibble(by_week), + by_age = as_tibble(by_age), + by_state = as_tibble(by_state), + by_sex = as_tibble(by_sex) + ) + +} diff --git a/R/public-health-labs-national.R b/R/public-health-labs-national.R new file mode 100644 index 0000000..649ebcb --- /dev/null +++ b/R/public-health-labs-national.R @@ -0,0 +1,57 @@ +#' Retrieve National Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC +#' +#' @return data frame +#' @references +#' @export +public_health_labs_national <- function() { + + xml2::read_html( + "https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html" + ) -> pg + + nat_tbl <- rvest::html_nodes(pg, xpath=".//table[contains(., 'National')]") + nat_rows <- rvest::html_nodes(nat_tbl, "tbody > tr") + lapply(nat_rows, function(.x) { + nat_tds <- rvest::html_nodes(.x, "td") + nat_tds <- gsub(",", "", rvest::html_text(nat_tds)) + as_tibble(as.data.frame( + as.list( + set_names( + nat_tds, sprintf("X%02d", 1:length(nat_tds)) + ) + ), + stringsAsFactors = FALSE + )) + }) -> nat_rows + nat_tbl <- do.call(rbind.data.frame, nat_rows) + + total <- set_names(nat_tbl[, 1:5], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + total$age_group <- "Overall" + + a1 <- set_names(nat_tbl[, c(1:2, 6:8)], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + a1$age_group <- "0-4 yr" + + a2 <- set_names(nat_tbl[, c(1:2, 9:11)], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + a2$age_group <- "5-17 yr" + + a3 <- set_names(nat_tbl[, c(1:2, 12:14)], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + a3$age_group <- "18-49 yr" + + a4 <- set_names(nat_tbl[, c(1:2, 15:17)], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + a4$age_group <- "50-64 yr" + + a5 <- set_names(nat_tbl[, c(1:2, 18:20)], c("week", "num_labs", "tested", "tested_pos", "pct_pos")) + a5$age_group <- "65+ yr" + + nat_tbl <- rbind(total, a1, a2, a3, a4, a5, stringsAsFactors = FALSE) + nat_tbl$region <- "National" + nat_tbl$source <- "Public Health Labs" + nat_tbl$week <- clean_int(nat_tbl$week) + nat_tbl$num_labs <- clean_int(nat_tbl$num_labs) + nat_tbl$tested <- clean_int(nat_tbl$tested) + nat_tbl$tested_pos <- clean_int(nat_tbl$tested_pos) + nat_tbl$pct_pos <- clean_num(nat_tbl$pct_pos)/100 + + nat_tbl[!is.na(nat_tbl$week),] + +} diff --git a/R/public-health-labs-regional.R b/R/public-health-labs-regional.R new file mode 100644 index 0000000..0caca25 --- /dev/null +++ b/R/public-health-labs-regional.R @@ -0,0 +1,42 @@ +#' Retrieve Regional Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC +#' +#' @return data frame +#' @references +#' @export +public_health_labs_regional <- function() { + + xml2::read_html( + "https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html" + ) -> pg + + regions <- sprintf("Region %d", 1:10) + + lapply(regions, function(region){ + + rvest::html_node( + pg, + xpath=sprintf(".//table[contains(., '%s (')]", region) + ) -> reg_tbl + + reg_tbl <- rvest::html_table(reg_tbl, header = TRUE, trim = TRUE) + + colnames(reg_tbl) <- c("week", "num_labs", "tested", "tested_pos", "pct_pos") + + reg_tbl$region <- region + reg_tbl$source <- "Public Health Labs" + + reg_tbl$week <- clean_int(reg_tbl$week) + reg_tbl$num_labs <- clean_int(reg_tbl$num_labs) + reg_tbl$tested <- clean_int(reg_tbl$tested) + reg_tbl$tested_pos <- clean_int(reg_tbl$tested_pos) + reg_tbl$pct_pos <- clean_num(reg_tbl$pct_pos)/100 + + as_tibble(reg_tbl[!is.na(reg_tbl$week),]) + + }) -> regs + + out <- do.call(rbind.data.frame, regs) + + as_tibble(out) + +} diff --git a/R/utils.R b/R/utils.R index 50bb206..2841561 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,3 +1,11 @@ +clean_int <- function(x) { + suppressWarnings(as.integer(gsub(",", "", x))) +} + +clean_num <- function(x) { + suppressWarnings(as.numeric(gsub(",", "", x))) +} + set_names <- function(object = nm, nm) { names(object) <- nm ; object } as_tibble <- function(x) { @@ -9,7 +17,7 @@ tibble <- function(...) { as_tibble(data.frame(..., stringsAsFactors = FALSE)) } -#' Tests whether a raw httr response or character vector has a byte order mark (BOM) +# Tests whether a raw httr response or character vector has a byte order mark (BOM) has_bom <- function(resp, encoding="UTF-8") { if (inherits(resp, "response")) { F <- resp$content[1:4] @@ -32,7 +40,7 @@ has_bom <- function(resp, encoding="UTF-8") { } } -#' Remove byte order mark (BOM) from \code{httr::response} object or character vector +# Remove byte order mark (BOM) from \code{httr::response} object or character vector sans_bom <- function(resp) { if (inherits(resp, "response")) { diff --git a/README.Rmd b/README.Rmd index 87a7663..80bd0b4 100644 --- a/README.Rmd +++ b/README.Rmd @@ -39,13 +39,15 @@ packageVersion("cdccovidview") ``` -```{r ex-01, fig.width = 10, fig.height = 7} +```{r ex-01, fig.width = 10, fig.height = 7, cache=TRUE} library(cdccovidview) library(hrbrthemes) library(tidyverse) hosp <- laboratory_confirmed_hospitalizations() +hosp + c( "0-4 yr", "5-17 yr", "18-49 yr", "50-64 yr", "65+ yr", "65-74 yr", "75-84 yr", "85+" ) -> age_f @@ -73,6 +75,46 @@ mutate(hosp, start = mmwr_week_to_date(mmwr_year, mmwr_week)) %>% ``` +### Clinical Labs + +```{r ex-02} +head(clinical_labs()) +``` + +### Public Health Labs + +```{r ex-03} +head(public_health_labs_national()) + +head(public_health_labs_regional()) +``` + +### Emergency Department Visits + +```{r ex-04} +head(nssp_er_visits_national()) + +head(nssp_er_visits_regional()) +``` + +### Mortality + +```{r ex-05} +head(mortality_surveillance_data()) +``` + +```{r ex-06} +pd <- provisional_death_counts() + +head(pd$by_week) + +head(pd$by_age) + +head(pd$by_state) + +head(pd$by_sex) +``` + ## cdccovidview Metrics ```{r cloc, echo=FALSE} diff --git a/README.md b/README.md index 08bc936..b3d39ff 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,8 @@ The following functions are implemented: - `about`: Display information about the data source - `age_groups`: Return age groups used in the surveillance - `available_seasons`: Show available seasons - - `has_bom`: Tests whether a raw httr response or character vector has - a byte order mark (BOM) + - `clinical_labs`: Retrieve U.S. Clinical Laboratories Reporting + SARS-CoV-2 Test Results to CDC - `laboratory_confirmed_hospitalizations`: Retrieve Laboratory-Confirmed COVID-19-Associated Hospitalizations - `mmwr_week_to_date`: Convert an MMWR year+week or year+week+day to a @@ -41,8 +41,20 @@ The following functions are implemented: - `mmwr_week`: Convert a Date to an MMWR day+week+year - `mmwr_weekday`: Convert a Date to an MMWR weekday - `mmwrid_map`: MMWR ID to Calendar Mappings - - `sans_bom`: Remove byte order mark (BOM) from httr::response object - or character vector + - `mortality_surveillance_data`: Retrieve NCHS Mortality Surveillance + Data + - `nssp_er_visits_national`: Retrieve National Syndromic Surveillance + Program (NSSP): Emergency Department Visits Percentage of Visits for + COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) + - `nssp_er_visits_regional`: Retrieve Regional Syndromic Surveillance + Program (NSSP): Emergency Department Visits Percentage of Visits for + COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) + - `provisional_death_counts`: Retrieve Provisional Death Counts for + Coronavirus Disease (COVID-19) + - `public_health_labs_national`: Retrieve National Surveillance of + U.S. State and Local Public Health Laboratories Reporting to CDC + - `public_health_labs_regional`: Retrieve Regional Surveillance of + U.S. State and Local Public Health Laboratories Reporting to CDC - `surveillance_areas`: Show network & network catchments ## Installation @@ -55,6 +67,8 @@ remotes::install_git("https://git.sr.ht/~hrbrmstr/cdccovidview") remotes::install_gitlab("hrbrmstr/cdccovidview") # or remotes::install_bitbucket("hrbrmstr/cdccovidview") +# or +remotes::install_github("hrbrmstr/cdccovidview") ``` NOTE: To use the ‘remotes’ install options you will need to have the @@ -77,6 +91,22 @@ library(tidyverse) hosp <- laboratory_confirmed_hospitalizations() +hosp +## # A tibble: 4,590 x 8 +## catchment network year mmwr_year mmwr_week age_category cumulative_rate weekly_rate +## +## 1 Entire Network COVID-NET 2020 2020 10 0-4 yr 0 0 +## 2 Entire Network COVID-NET 2020 2020 11 0-4 yr 0 0 +## 3 Entire Network COVID-NET 2020 2020 12 0-4 yr 0 0 +## 4 Entire Network COVID-NET 2020 2020 13 0-4 yr 0.3 0.3 +## 5 Entire Network COVID-NET 2020 2020 14 0-4 yr 0.6 0.3 +## 6 Entire Network COVID-NET 2020 2020 15 0-4 yr NA NA +## 7 Entire Network COVID-NET 2020 2020 16 0-4 yr NA NA +## 8 Entire Network COVID-NET 2020 2020 17 0-4 yr NA NA +## 9 Entire Network COVID-NET 2020 2020 18 0-4 yr NA NA +## 10 Entire Network COVID-NET 2020 2020 19 0-4 yr NA NA +## # … with 4,580 more rows + c( "0-4 yr", "5-17 yr", "18-49 yr", "50-64 yr", "65+ yr", "65-74 yr", "75-84 yr", "85+" ) -> age_f @@ -105,12 +135,142 @@ mutate(hosp, start = mmwr_week_to_date(mmwr_year, mmwr_week)) %>% +### Clinical Labs + +``` r +head(clinical_labs()) +## week num_labs tested tested_pos pct_pos region source +## 1 202011 26 2785 182 0.065 National Clinical Labs +## 2 202012 41 18494 1149 0.062 National Clinical Labs +## 3 202013 50 37390 2966 0.079 National Clinical Labs +## 4 202014 37 36468 2798 0.077 National Clinical Labs +``` + +### Public Health Labs + +``` r +head(public_health_labs_national()) +## week num_labs tested tested_pos pct_pos age_group region source +## 1 202010 73 8049 945 0.117 Overall National Public Health Labs +## 2 202011 79 32072 3292 0.103 Overall National Public Health Labs +## 3 202012 80 63369 6494 0.103 Overall National Public Health Labs +## 4 202013 79 56443 9529 0.169 Overall National Public Health Labs +## 5 202014 75 65917 12177 0.185 Overall National Public Health Labs +## 6 202010 73 212 9 0.043 0-4 yr National Public Health Labs + +head(public_health_labs_regional()) +## week num_labs tested tested_pos pct_pos region source +## 1 202010 8 619 46 0.074 Region 1 Public Health Labs +## 2 202011 17 3208 194 0.061 Region 1 Public Health Labs +## 3 202012 18 9608 732 0.076 Region 1 Public Health Labs +## 4 202013 16 4625 700 0.151 Region 1 Public Health Labs +## 5 202014 15 6123 1611 0.263 Region 1 Public Health Labs +## 6 202010 5 1381 193 0.140 Region 2 Public Health Labs +``` + +### Emergency Department Visits + +``` r +head(nssp_er_visits_national()) +## week num_fac total_ed_visits visits pct_visits visit_type region source year +## 1 40 3255 2146776 19503 0.009 ili National Emergency Departments 2019 +## 2 41 3249 2106999 20457 0.010 ili National Emergency Departments 2019 +## 3 42 3256 2101358 22515 0.011 ili National Emergency Departments 2019 +## 4 43 3254 2122427 23776 0.011 ili National Emergency Departments 2019 +## 5 44 3295 2087335 25466 0.012 ili National Emergency Departments 2019 +## 6 45 3315 2137854 29948 0.014 ili National Emergency Departments 2019 + +head(nssp_er_visits_regional()) +## week num_fac total_ed_visits visits pct_visits visit_type region source year +## 1 40 3255 2146776 19503 0.009 ili Region 1 Emergency Departments 2019 +## 2 41 3249 2106999 20457 0.010 ili Region 1 Emergency Departments 2019 +## 3 42 3256 2101358 22515 0.011 ili Region 1 Emergency Departments 2019 +## 4 43 3254 2122427 23776 0.011 ili Region 1 Emergency Departments 2019 +## 5 44 3295 2087335 25466 0.012 ili Region 1 Emergency Departments 2019 +## 6 45 3315 2137854 29948 0.014 ili Region 1 Emergency Departments 2019 +``` + +### Mortality + +``` r +head(mortality_surveillance_data()) +## year week total_deaths deaths pct_deaths cause region source +## 1 2019 40 52452 0 0 COVID-19 National NCHS +## 2 2019 41 52860 0 0 COVID-19 National NCHS +## 3 2019 42 54129 0 0 COVID-19 National NCHS +## 4 2019 43 53914 0 0 COVID-19 National NCHS +## 5 2019 44 53980 0 0 COVID-19 National NCHS +## 6 2019 45 55468 0 0 COVID-19 National NCHS +``` + +``` r +pd <- provisional_death_counts() + +head(pd$by_week) +## week covid_deaths total_deaths percent_expected_deaths pneumonia_deaths pneumonia_and_covid_deaths +## 2 2020-02-01 0 56402 0.95 3618 0 +## 3 2020-02-08 0 56737 0.95 3601 0 +## 4 2020-02-15 0 55273 0.94 3580 0 +## 5 2020-02-22 0 54859 0.94 3427 0 +## 6 2020-02-29 5 54513 0.95 3464 3 +## 7 2020-03-07 18 53801 0.93 3552 11 +## all_influenza_deaths_j09_j11 +## 2 452 +## 3 483 +## 4 489 +## 5 502 +## 6 573 +## 7 555 + +head(pd$by_age) +## age_group covid_deaths total_deaths percent_expected_deaths pneumonia_deaths pneumonia_and_covid_deaths +## 12 All ages 4984 511424 0.89 36423 2341 +## 13 Under 1 yr 0 2727 0.65 19 0 +## 14 1-4 yr 1 552 0.76 27 1 +## 15 5-14 yr 1 809 0.73 26 0 +## 16 15-24 yr 6 4638 0.81 87 2 +## 17 25-34 yr 46 9624 0.86 257 21 +## all_influenza_deaths_j09_j11 +## 12 4541 +## 13 9 +## 14 26 +## 15 34 +## 16 35 +## 17 106 + +head(pd$by_state) +## state covid_deaths total_deaths percent_expected_deaths pneumonia_deaths pneumonia_and_covid_deaths +## 25 Alabama 14 9220 0.87 539 4 +## 26 Alaska 1 627 0.75 31 1 +## 27 Arizona 26 11862 0.97 748 13 +## 28 Arkansas 3 5938 0.92 372 2 +## 29 California 175 52505 0.94 4170 96 +## 30 Colorado 62 7787 0.98 493 33 +## all_influenza_deaths_j09_j11 +## 25 75 +## 26 3 +## 27 95 +## 28 62 +## 29 511 +## 30 77 + +head(pd$by_sex) +## sex covid_deaths total_deaths percent_expected_deaths pneumonia_deaths pneumonia_and_covid_deaths +## 79 Male 2993 262727 0.90 19129 1374 +## 80 Female 1991 248679 0.89 17294 967 +## 81 Unknown 0 18 0.82 0 0 +## all_influenza_deaths_j09_j11 +## 79 2262 +## 80 2279 +## 81 0 +``` + ## cdccovidview Metrics -| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | -| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: | -| R | 11 | 0.92 | 200 | 0.85 | 75 | 0.79 | 136 | 0.82 | -| Rmd | 1 | 0.08 | 35 | 0.15 | 20 | 0.21 | 30 | 0.18 | +| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | +| :--- | -------: | ---: | --: | --: | ----------: | --: | -------: | --: | +| R | 18 | 0.95 | 433 | 0.9 | 145 | 0.8 | 173 | 0.8 | +| Rmd | 1 | 0.05 | 47 | 0.1 | 36 | 0.2 | 44 | 0.2 | ## Code of Conduct diff --git a/man/clinical_labs.Rd b/man/clinical_labs.Rd new file mode 100644 index 0000000..235221b --- /dev/null +++ b/man/clinical_labs.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/clinical-labs.R +\name{clinical_labs} +\alias{clinical_labs} +\title{Retrieve U.S. Clinical Laboratories Reporting SARS-CoV-2 Test Results to CDC} +\usage{ +clinical_labs() +} +\value{ +data frame +} +\description{ +Retrieve U.S. Clinical Laboratories Reporting SARS-CoV-2 Test Results to CDC +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/reporting-cov2-results.html} +} diff --git a/man/has_bom.Rd b/man/has_bom.Rd deleted file mode 100644 index e311835..0000000 --- a/man/has_bom.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{has_bom} -\alias{has_bom} -\title{Tests whether a raw httr response or character vector has a byte order mark (BOM)} -\usage{ -has_bom(resp, encoding = "UTF-8") -} -\description{ -Tests whether a raw httr response or character vector has a byte order mark (BOM) -} diff --git a/man/mortality_surveillance_data.Rd b/man/mortality_surveillance_data.Rd new file mode 100644 index 0000000..28d3fdc --- /dev/null +++ b/man/mortality_surveillance_data.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mortality.R +\name{mortality_surveillance_data} +\alias{mortality_surveillance_data} +\title{Retrieve NCHS Mortality Surveillance Data} +\usage{ +mortality_surveillance_data() +} +\value{ +data frame +} +\description{ +Retrieve NCHS Mortality Surveillance Data +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nchs-data.html} +} diff --git a/man/nssp_er_visits_national.Rd b/man/nssp_er_visits_national.Rd new file mode 100644 index 0000000..ff80690 --- /dev/null +++ b/man/nssp_er_visits_national.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/nssp-cd.R +\name{nssp_er_visits_national} +\alias{nssp_er_visits_national} +\title{Retrieve National Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI)} +\usage{ +nssp_er_visits_national() +} +\value{ +data frame +} +\description{ +Retrieve National Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html} +} diff --git a/man/nssp_er_visits_regional.Rd b/man/nssp_er_visits_regional.Rd new file mode 100644 index 0000000..ebe78bf --- /dev/null +++ b/man/nssp_er_visits_regional.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/nss-cd-reg.R +\name{nssp_er_visits_regional} +\alias{nssp_er_visits_regional} +\title{Retrieve Regional Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI)} +\usage{ +nssp_er_visits_regional() +} +\value{ +data frame +} +\description{ +Retrieve Regional Syndromic Surveillance Program (NSSP): Emergency Department Visits Percentage of Visits for COVID-19-Like Illness (CLI) or Influenza-like Illness (ILI) +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html} +} diff --git a/man/provisional_death_counts.Rd b/man/provisional_death_counts.Rd new file mode 100644 index 0000000..be710e9 --- /dev/null +++ b/man/provisional_death_counts.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/provisional-deaths.R +\name{provisional_death_counts} +\alias{provisional_death_counts} +\title{Retrieve Provisional Death Counts for Coronavirus Disease (COVID-19)} +\usage{ +provisional_death_counts() +} +\value{ +a list with 4 named elements: \code{by_week}, \code{by_age}, \code{by_state}, \code{by_sex} +} +\description{ +Retrieve Provisional Death Counts for Coronavirus Disease (COVID-19) +} +\note{ +Please see the indicated reference for all the caveats and precise meanings for each field. Also, +this function used the JSON API (\url{https://data.cdc.gov/resource/hc4f-j6nb.json}) +} +\references{ +\url{https://data.cdc.gov/api/views/hc4f-j6nb/rows.csv?accessType=DOWNLOAD&bom=true&format=true} +} diff --git a/man/public_health_labs_national.Rd b/man/public_health_labs_national.Rd new file mode 100644 index 0000000..06d4615 --- /dev/null +++ b/man/public_health_labs_national.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/public-health-labs-national.R +\name{public_health_labs_national} +\alias{public_health_labs_national} +\title{Retrieve National Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC} +\usage{ +public_health_labs_national() +} +\value{ +data frame +} +\description{ +Retrieve National Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html} +} diff --git a/man/public_health_labs_regional.Rd b/man/public_health_labs_regional.Rd new file mode 100644 index 0000000..7a77402 --- /dev/null +++ b/man/public_health_labs_regional.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/public-health-labs-regional.R +\name{public_health_labs_regional} +\alias{public_health_labs_regional} +\title{Retrieve Regional Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC} +\usage{ +public_health_labs_regional() +} +\value{ +data frame +} +\description{ +Retrieve Regional Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC +} +\references{ +\url{https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html} +} diff --git a/man/sans_bom.Rd b/man/sans_bom.Rd deleted file mode 100644 index 2e3fa58..0000000 --- a/man/sans_bom.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{sans_bom} -\alias{sans_bom} -\title{Remove byte order mark (BOM) from \code{httr::response} object or character vector} -\usage{ -sans_bom(resp) -} -\description{ -Remove byte order mark (BOM) from \code{httr::response} object or character vector -}