@ -0,0 +1,24 @@ | |||
#' Retrieve U.S. Clinical Laboratories Reporting SARS-CoV-2 Test Results to CDC | |||
#' | |||
#' @references <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/reporting-cov2-results.html> | |||
#' @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),]) | |||
} |
@ -0,0 +1,47 @@ | |||
#' Retrieve NCHS Mortality Surveillance Data | |||
#' | |||
#' @return data frame | |||
#' @references <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nchs-data.html> | |||
#' @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),]) | |||
} |
@ -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 <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html> | |||
#' @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) | |||
} |
@ -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 <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/nssp-regions.html> | |||
#' @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),]) | |||
} |
@ -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 (<https://data.cdc.gov/resource/hc4f-j6nb.json>) | |||
#' @return a list with 4 named elements: `by_week`, `by_age`, `by_state`, `by_sex` | |||
#' @references <https://data.cdc.gov/api/views/hc4f-j6nb/rows.csv?accessType=DOWNLOAD&bom=true&format=true> | |||
#' @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) | |||
) | |||
} |
@ -0,0 +1,57 @@ | |||
#' Retrieve National Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC | |||
#' | |||
#' @return data frame | |||
#' @references <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html> | |||
#' @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),] | |||
} |
@ -0,0 +1,42 @@ | |||
#' Retrieve Regional Surveillance of U.S. State and Local Public Health Laboratories Reporting to CDC | |||
#' | |||
#' @return data frame | |||
#' @references <https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/04102020/labs-regions.html> | |||
#' @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) | |||
} |
@ -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} | |||
} |
@ -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) | |||
} |
@ -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} | |||
} |
@ -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} | |||
} |
@ -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} | |||
} |
@ -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} | |||
} |
@ -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} | |||
} |
@ -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} | |||
} |
@ -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 | |||
} |