boB Rudis
4 years ago
30 changed files with 828 additions and 8 deletions
@ -0,0 +1,2 @@ |
|||||
|
YEAR: 2020 |
||||
|
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||||
|
# MIT License |
||||
|
|
||||
|
Copyright (c) 2020 Bob Rudis |
||||
|
|
||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
of this software and associated documentation files (the "Software"), to deal |
||||
|
in the Software without restriction, including without limitation the rights |
||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
copies of the Software, and to permit persons to whom the Software is |
||||
|
furnished to do so, subject to the following conditions: |
||||
|
|
||||
|
The above copyright notice and this permission notice shall be included in all |
||||
|
copies or substantial portions of the Software. |
||||
|
|
||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
|
SOFTWARE. |
@ -1,4 +1,19 @@ |
|||||
# Generated by roxygen2: do not edit by hand |
# Generated by roxygen2: do not edit by hand |
||||
|
|
||||
|
export(about) |
||||
|
export(age_groups) |
||||
|
export(available_seasons) |
||||
|
export(laboratory_confirmed_hospitalizations) |
||||
|
export(mmwr_week) |
||||
|
export(mmwr_week_to_date) |
||||
|
export(mmwr_weekday) |
||||
|
export(mmwrid_map) |
||||
|
export(surveillance_areas) |
||||
|
import(MMWRweek) |
||||
import(httr) |
import(httr) |
||||
|
importFrom(htmltools,HTML) |
||||
|
importFrom(htmltools,div) |
||||
|
importFrom(htmltools,html_print) |
||||
importFrom(jsonlite,fromJSON) |
importFrom(jsonlite,fromJSON) |
||||
|
importFrom(memoise,memoise) |
||||
|
importFrom(xml2,read_html) |
||||
|
@ -0,0 +1,8 @@ |
|||||
|
httr::user_agent( |
||||
|
sprintf( |
||||
|
"cdccovidview package v%s: (<%s>)", |
||||
|
utils::packageVersion("cdccovidview"), |
||||
|
utils::packageDescription("cdccovidview")$URL |
||||
|
) |
||||
|
) -> .CDCCOVIDVIEW_UA |
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
#' Display information about the data source |
||||
|
#' |
||||
|
#' @param display if `html` (the default) a formatted version of |
||||
|
#' the description is provided, otherwise a plaintext version |
||||
|
#' will be provided. |
||||
|
#' @export |
||||
|
about <- function(display = c("html", "text")) { |
||||
|
|
||||
|
display <- match.arg(display, c("html", "text")) |
||||
|
|
||||
|
p <- app_params() |
||||
|
|
||||
|
if (display == "html") { |
||||
|
|
||||
|
p$app_text[ |
||||
|
p$app_text$description %in% c("HTMLSplashDisclaimer"), |
||||
|
]$text -> splsh |
||||
|
|
||||
|
htmltools::html_print( |
||||
|
htmltools::div( |
||||
|
htmltools::HTML(splsh), |
||||
|
style = "margin:10%; font-family:sans-serif" |
||||
|
) |
||||
|
) |
||||
|
|
||||
|
} else { |
||||
|
|
||||
|
p$app_text[ |
||||
|
p$app_text$description %in% c("ImageExportDisclaimer"), |
||||
|
]$text -> splsh |
||||
|
|
||||
|
cat(strwrap(splsh), sep="\n") |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
#' Return age groups used in the surveillance |
||||
|
#' |
||||
|
#' @return character vector |
||||
|
#' @export |
||||
|
age_groups <- function() { |
||||
|
|
||||
|
p <- app_params() |
||||
|
|
||||
|
rev(p$ages$label) |
||||
|
|
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
.app_params <- function() { |
||||
|
|
||||
|
httr::GET( |
||||
|
url = "https://gis.cdc.gov/grasp/COVIDNet/InitJSON/covid_phase03_init.json", |
||||
|
.CDCCOVIDVIEW_UA |
||||
|
) -> res |
||||
|
|
||||
|
httr::stop_for_status(res) |
||||
|
|
||||
|
if (has_bom(res)) { |
||||
|
out <- sans_bom(res) |
||||
|
} else { |
||||
|
out <- httr::content(res, as = "text") |
||||
|
} |
||||
|
|
||||
|
out <- jsonlite::fromJSON(out) |
||||
|
|
||||
|
out |
||||
|
|
||||
|
} |
||||
|
|
||||
|
app_params <- memoise::memoise(.app_params) |
@ -1,9 +1,46 @@ |
|||||
#' ... |
#' Weekly Surveillance Summary of U.S. COVID-19 Activity |
||||
#' |
#' |
||||
|
#' The U.S. Centers for Disease Control provides weekly summary and |
||||
|
#' interpretation of key indicators that have been adapted to track the COVID-19 |
||||
|
#' pandemic in the United States. Tools are provided to retrive data from both |
||||
|
#' COVIDView |
||||
|
#' (<https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/index.html>) |
||||
|
#' and COVID-NET (<https://gis.cdc.gov/grasp/COVIDNet/COVID19_3.html>). |
||||
|
#' |
||||
|
#' The Coronavirus Disease 2019 (COVID-19)-Associated Hospitalization |
||||
|
#' Surveillance Network (COVID-NET) conducts population-based surveillance for |
||||
|
#' laboratory-confirmed COVID-19-associated hospitalizations in children |
||||
|
#' (persons younger than 18 years) and adults. The current network covers nearly |
||||
|
#' 100 counties in the 10 Emerging Infections Program (EIP) states (CA, CO, CT, |
||||
|
#' GA, MD, MN, NM, NY, OR, and TN) and four additional states through the |
||||
|
#' Influenza Hospitalization Surveillance Project (IA, MI, OH, and UT). The |
||||
|
#' network represents approximately 10% of US population (~32 million people). |
||||
|
#' |
||||
|
#' Cases are identified by reviewing hospital, laboratory, and admission |
||||
|
#' databases and infection control logs for patients hospitalized with a |
||||
|
#' documented positive SARS-CoV-2 test. |
||||
|
#' |
||||
|
#' Data gathered are used to estimate age-specific hospitalization rates on a |
||||
|
#' weekly basis and describe characteristics of persons hospitalized with |
||||
|
#' COVID-19. Laboratory confirmation is dependent on clinician-ordered |
||||
|
#' SARS-CoV-2 testing. Therefore, the rates provided are likely to be |
||||
|
#' underestimated as COVID-19-associated hospitalizations can be missed due to |
||||
|
#' test availability and provider or facility testing practices. |
||||
|
#' |
||||
|
#' COVID-NET hospitalization data are preliminary and subject to change as more |
||||
|
#' data become available. Please use the following citation when referencing |
||||
|
#' these data: “COVID-NET: COVID-19-Associated Hospitalization Surveillance |
||||
|
#' Network, Centers for Disease Control and Prevention. WEBSITE. Accessed on |
||||
|
#' DATE”. |
||||
|
#' |
||||
#' @md |
#' @md |
||||
#' @name cdccovidview |
#' @name cdccovidview |
||||
#' @keywords internal |
#' @keywords internal |
||||
#' @author Bob Rudis (bob@@rud.is) |
#' @author Bob Rudis (bob@@rud.is) |
||||
#' @import httr |
#' @import httr |
||||
#' @importFrom jsonlite fromJSON |
#' @importFrom jsonlite fromJSON |
||||
|
#' @importFrom memoise memoise |
||||
|
#' @importFrom htmltools html_print HTML div |
||||
|
#' @importFrom xml2 read_html |
||||
|
#' @import MMWRweek |
||||
"_PACKAGE" |
"_PACKAGE" |
||||
|
@ -0,0 +1,68 @@ |
|||||
|
#' Retrieve Laboratory-Confirmed COVID-19-Associated Hospitalizations |
||||
|
#' |
||||
|
#' This function grabs all data for all networks, catchments, seasons, and ages. |
||||
|
#' In the future there will be ways of selecting just the desired target areas. |
||||
|
#' |
||||
|
#' @return data frame |
||||
|
#' @export |
||||
|
laboratory_confirmed_hospitalizations <- function() { |
||||
|
|
||||
|
p <- cdccovidview:::app_params() |
||||
|
|
||||
|
catch <- p$catchments[, c("networkid", "name", "area", "catchmentid")] |
||||
|
|
||||
|
age_grp <- p$ages[, c("label", "ageid")] |
||||
|
|
||||
|
seas <- p$seasons[, "seasonid", drop=FALSE] |
||||
|
colnames(seas) <- "ID" |
||||
|
|
||||
|
.get_one <- function(net_id = 1, cat_id = 22) { |
||||
|
|
||||
|
unclass(jsonlite::toJSON(list( |
||||
|
AppVersion = jsonlite::unbox("Public"), |
||||
|
networkid = jsonlite::unbox(as.integer(net_id)), |
||||
|
catchmentid = jsonlite::unbox(as.integer(cat_id)), |
||||
|
seasons = seas, |
||||
|
agegroups = data.frame(ID = 1:9L) |
||||
|
))) -> body |
||||
|
|
||||
|
c( |
||||
|
`Content-Type` = 'application/json;charset=UTF-8' |
||||
|
) -> headers |
||||
|
|
||||
|
httr::POST( |
||||
|
url = 'https://gis.cdc.gov/grasp/covid19_3_api/PostPhase03DownloadData', httr::add_headers(.headers=headers), |
||||
|
.CDCCOVIDVIEW_UA, |
||||
|
body = body |
||||
|
) -> res |
||||
|
|
||||
|
httr::stop_for_status(res) |
||||
|
|
||||
|
if (has_bom(res)) { |
||||
|
out <- sans_bom(res) |
||||
|
} else { |
||||
|
out <- httr::content(res, as = "text") |
||||
|
} |
||||
|
|
||||
|
out <- jsonlite::fromJSON(out) |
||||
|
|
||||
|
out <- as_tibble(out$datadownload) |
||||
|
|
||||
|
colnames(out) <- gsub("-", "_", colnames(out)) |
||||
|
|
||||
|
out |
||||
|
|
||||
|
} |
||||
|
|
||||
|
lapply(1:nrow(catch), function(.idx) { |
||||
|
.get_one( |
||||
|
net_id = catch$networkid[.idx], |
||||
|
cat_id = catch$catchmentid[.idx] |
||||
|
) |
||||
|
}) -> res |
||||
|
|
||||
|
out <- do.call(rbind.data.frame, res) |
||||
|
|
||||
|
as_tibble(out) |
||||
|
|
||||
|
} |
@ -0,0 +1,118 @@ |
|||||
|
# THIS IS NOT EXPORTED FROM MMWRweek but I need it |
||||
|
# Find start date for a calendar year |
||||
|
# |
||||
|
# Finds the state date given a numeric calendar year |
||||
|
# @author Jarad Niemi \email{niemi@@iastate.edu} |
||||
|
.start_date = function(year) { |
||||
|
# Finds start state for this calendar year |
||||
|
# Fix by @bastistician |
||||
|
jan1 <- as.Date(paste0(year, '-01-01')) |
||||
|
wday <- as.numeric(strftime(jan1, "%w")) # Sunday is 0 |
||||
|
jan1 - wday + 7*(wday>3) |
||||
|
} |
||||
|
|
||||
|
# I discovered why 1962!: https://www.cdc.gov/mmwr/preview/mmwrhtml/su6004a9.htm |
||||
|
.tmp <- lapply(1962:2050, .start_date) |
||||
|
|
||||
|
mapply(function(.x, .y) { |
||||
|
tibble::tibble( |
||||
|
wk_start = seq(.tmp[[.x]], .tmp[[.y]], "1 week"), |
||||
|
wk_end = wk_start + 6, |
||||
|
year_wk_num = 1:length(wk_start) |
||||
|
) -> tmp |
||||
|
tmp[-nrow(tmp),] |
||||
|
}, 1:(length(.tmp)-1), 2:length(.tmp), SIMPLIFY=FALSE) -> mmwrid_map |
||||
|
|
||||
|
mmwrid_map <- Reduce(rbind.data.frame, mmwrid_map) |
||||
|
mmwrid_map$mmwrid <- 1:nrow(mmwrid_map) |
||||
|
|
||||
|
#' @title MMWR ID to Calendar Mappings |
||||
|
#' @md |
||||
|
#' @description The CDC uses a unique "Morbidity and Mortality Weekly Report" identifier |
||||
|
#' for each week that starts at 1 (Ref: < https://www.cdc.gov/mmwr/preview/mmwrhtml/su6004a9.htm>). |
||||
|
#' This data frame consists of 4 columns: |
||||
|
#' - `wk_start`: Start date (Sunday) for the week (`Date`) |
||||
|
#' - `wk_end`: End date (Saturday) for the week (`Date`) |
||||
|
#' - `year_wk_num`: The week of the calendar year |
||||
|
#' - `mmwrid`: The unique MMWR identifier |
||||
|
#' These can be "left-joined" to data provided from the CDC to perform MMWR identifier |
||||
|
#' to date mappings. |
||||
|
#' @docType data |
||||
|
#' @name mmwrid_map |
||||
|
#' @format A data frame with 4,592 rows and 4 columns |
||||
|
#' @export |
||||
|
NULL |
||||
|
|
||||
|
#' Convert a Date to an MMWR day+week+year |
||||
|
#' |
||||
|
#' This is a reformat and re-export of a function in the `MMWRweek` package. |
||||
|
#' It provides a snake case version of its counterpart, produces a `tibble` |
||||
|
#' |
||||
|
#' @md |
||||
|
#' @param x a vector of `Date` objects or a character vector in `YYYY-mm-dd` format. |
||||
|
#' @return data frame (tibble) |
||||
|
#' @export |
||||
|
#' @examples |
||||
|
#' mwk <- mmwr_week(Sys.Date()) |
||||
|
mmwr_week <- function(x) { |
||||
|
x <- as.Date(x) |
||||
|
x <- setNames(MMWRweek::MMWRweek(x), c("mmwr_year", "mmwr_week", "mmwr_day")) |
||||
|
class(x) <- c("tbl_df", "tbl", "data.frame") |
||||
|
x |
||||
|
} |
||||
|
|
||||
|
#' Convert a Date to an MMWR weekday |
||||
|
#' |
||||
|
#' This is a reformat and re-export of a function in the `MMWRweek` package. |
||||
|
#' It provides a snake case version of its counterpart, produces a `factor` of |
||||
|
#' weekday names (Sunday-Saturday). |
||||
|
#' |
||||
|
#' @md |
||||
|
#' @note Weekday names are explicitly mapped to "Sunday-Saturday" or "Sun-Sat" and |
||||
|
#' do not change with your locale. |
||||
|
#' @param x a vector of `Date` objects or a character vector in `YYYY-mm-dd` format. |
||||
|
#' @param abbr (logical) if `TRUE`, return abbreviated weekday names, otherwise full |
||||
|
#' weekday names (see Note). |
||||
|
#' @return ordered factor |
||||
|
#' @export |
||||
|
#' @examples |
||||
|
#' mwday <- mmwr_weekday(Sys.Date()) |
||||
|
mmwr_weekday <- function(x, abbr = FALSE) { |
||||
|
x <- as.Date(x) |
||||
|
x <- MMWRweek::MMWRweekday(x) |
||||
|
if (abbr) { |
||||
|
x <- ordered( |
||||
|
x, |
||||
|
levels=c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), |
||||
|
labels = c("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat") |
||||
|
) |
||||
|
} |
||||
|
x |
||||
|
} |
||||
|
|
||||
|
#' Convert an MMWR year+week or year+week+day to a Date object |
||||
|
#' |
||||
|
#' This is a reformat and re-export of a function in the `MMWRweek` package. |
||||
|
#' It provides a snake case version of its counterpart and produces a vector |
||||
|
#' of `Date` objects that corresponds to the input MMWR year+week or year+week+day |
||||
|
#' vectors. This also adds some parameter checking and cleanup to avoid exceptions. |
||||
|
#' |
||||
|
#' @md |
||||
|
#' @param year,week,day Year, week and month vectors. All must be the same length |
||||
|
#' unless `day` is `NULL`. |
||||
|
#' @return vector of `Date` objects |
||||
|
#' @export |
||||
|
#' @examples |
||||
|
#' mwd <- mmwr_week_to_date(2016,10,3) |
||||
|
mmwr_week_to_date <- function(year, week, day=NULL) { |
||||
|
|
||||
|
year <- as.numeric(year) |
||||
|
week <- as.numeric(week) |
||||
|
day <- if (!is.null(day)) as.numeric(day) else rep(1, length(week)) |
||||
|
|
||||
|
week <- ifelse(0 < week & week < 54, week, NA) |
||||
|
|
||||
|
as.Date(ifelse(is.na(week), NA, MMWRweek::MMWRweek2Date(year, week, day)), |
||||
|
origin="1970-01-01") |
||||
|
|
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
#' Show available seasons |
||||
|
#' |
||||
|
#' @return data frame |
||||
|
#' @export |
||||
|
available_seasons <- function() { |
||||
|
|
||||
|
p <- app_params() |
||||
|
|
||||
|
out <- p$seasons[, c("description", "seasonid", "startweek", "endweek")] |
||||
|
|
||||
|
as_tibble(out) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1,13 @@ |
|||||
|
#' Show network & network catchments |
||||
|
#' |
||||
|
#' @return data frame |
||||
|
#' @export |
||||
|
surveillance_areas <- function() { |
||||
|
|
||||
|
p <- app_params() |
||||
|
|
||||
|
out <- p$catchments[,c("name", "area")] |
||||
|
|
||||
|
as_tibble(out) |
||||
|
|
||||
|
} |
@ -0,0 +1,66 @@ |
|||||
|
set_names <- function(object = nm, nm) { names(object) <- nm ; object } |
||||
|
|
||||
|
as_tibble <- function(x) { |
||||
|
class(x) <- c("tbl_df", "tbl", "data.frame") |
||||
|
x |
||||
|
} |
||||
|
|
||||
|
tibble <- function(...) { |
||||
|
as_tibble(data.frame(..., stringsAsFactors = FALSE)) |
||||
|
} |
||||
|
|
||||
|
#' 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] |
||||
|
switch(encoding, |
||||
|
`UTF-8`=F[1]==as.raw(0xef) & F[2]==as.raw(0xbb) & F[3]==as.raw(0xbf), |
||||
|
`UTF-16`=F[1]==as.raw(0xff) & F[2]==as.raw(0xfe), |
||||
|
`UTF-16BE`=F[1]==as.raw(0xfe) & F[2]==as.raw(0xff), |
||||
|
{ message("Unsupported encoding") ; return(NA) } |
||||
|
) |
||||
|
} else if (inherits(resp, "character")) { |
||||
|
switch(encoding, |
||||
|
`UTF-8`=grepl("^", resp[1]), |
||||
|
`UTF-16`=grepl("^ÿþ", resp[1]), |
||||
|
`UTF-16BE`=grepl("^þÿ", resp[1]), |
||||
|
{ message("Unsupported encoding") ; return(NA) } |
||||
|
) |
||||
|
} else { |
||||
|
message("Expected either an httr::response object or a character") |
||||
|
return(NA) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#' Remove byte order mark (BOM) from \code{httr::response} object or character vector |
||||
|
sans_bom <- function(resp) { |
||||
|
|
||||
|
if (inherits(resp, "response")) { |
||||
|
|
||||
|
F <- resp$content[1:4] |
||||
|
if (F[1]==as.raw(0xef) & F[2]==as.raw(0xbb) & F[3]==as.raw(0xbf)) { |
||||
|
iconv(readBin(resp$content[4:length(resp$content)], character()), from="UTF-8", to="UTF-8") |
||||
|
} else if (F[1]==as.raw(0xff) & F[2]==as.raw(0xfe)) { |
||||
|
iconv(readBin(resp$content[3:length(resp$content)], character()), from="UTF-16", to="UTF-8") |
||||
|
} else if (F[1]==as.raw(0xfe) & F[2]==as.raw(0xff)) { |
||||
|
iconv(readBin(resp$content[3:length(resp$content)], character()), from="UTF-16BE", to="UTF-8") |
||||
|
} else { |
||||
|
stop("Did not detect a BOM in the httr::response object content.", call.=FALSE) |
||||
|
} |
||||
|
|
||||
|
} else if (inherits(resp, "character")) { |
||||
|
|
||||
|
if (grepl("^", resp[1])) { |
||||
|
iconv(readBin(sub("^", "", resp), character()), from="UTF-8", to="UTF-8") |
||||
|
} else if (grepl("^ÿþ", resp[1])) { |
||||
|
iconv(readBin(sub("^ÿþ", "", resp), character()), from="UTF-16", to="UTF-8") |
||||
|
} else if (grepl("^þÿ", resp[1])) { |
||||
|
iconv(readBin(sub("^þÿ", "", resp), character()), from="UTF-16BE", to="UTF-8") |
||||
|
} else { |
||||
|
stop("Did not detect a BOM in the content.", call.=FALSE) |
||||
|
} |
||||
|
|
||||
|
} else { |
||||
|
stop("Expected either an httr::response object or a character", call.=FALSE) |
||||
|
} |
||||
|
} |
@ -0,0 +1,119 @@ |
|||||
|
|
||||
|
[![Project Status: Active – The project has reached a stable, usable |
||||
|
state and is being actively |
||||
|
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
||||
|
[![Signed |
||||
|
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) |
||||
|
![Signed commit |
||||
|
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) |
||||
|
[![Linux build |
||||
|
Status](https://travis-ci.org/hrbrmstr/cdccovidview.svg?branch=master)](https://travis-ci.org/hrbrmstr/cdccovidview) |
||||
|
![Minimal R |
||||
|
Version](https://img.shields.io/badge/R%3E%3D-3.2.0-blue.svg) |
||||
|
![License](https://img.shields.io/badge/License-MIT-blue.svg) |
||||
|
|
||||
|
# cdccovidview |
||||
|
|
||||
|
Weekly Surveillance Summary of U.S. COVID-19 Activity |
||||
|
|
||||
|
## Description |
||||
|
|
||||
|
The U.S. Centers for Disease Control provides weekly summary and |
||||
|
interpretation of key indicators that have been adapted to track the |
||||
|
COVID-19 pandemic in the United States. Tools are provided to retrive |
||||
|
data from both COVIDView |
||||
|
(<https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/index.html>) |
||||
|
and COVID-NET (<https://gis.cdc.gov/grasp/COVIDNet/COVID19_3.html>). |
||||
|
|
||||
|
## What’s Inside The Tin |
||||
|
|
||||
|
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) |
||||
|
- `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 |
||||
|
Date object |
||||
|
- `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 |
||||
|
- `surveillance_areas`: Show network & network catchments |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
``` r |
||||
|
remotes::install_git("https://git.rud.is/hrbrmstr/cdccovidview.git") |
||||
|
# or |
||||
|
remotes::install_git("https://git.sr.ht/~hrbrmstr/cdccovidview") |
||||
|
# or |
||||
|
remotes::install_gitlab("hrbrmstr/cdccovidview") |
||||
|
# or |
||||
|
remotes::install_bitbucket("hrbrmstr/cdccovidview") |
||||
|
``` |
||||
|
|
||||
|
NOTE: To use the ‘remotes’ install options you will need to have the |
||||
|
[{remotes} package](https://github.com/r-lib/remotes) installed. |
||||
|
|
||||
|
## Usage |
||||
|
|
||||
|
``` r |
||||
|
library(cdccovidview) |
||||
|
|
||||
|
# current version |
||||
|
packageVersion("cdccovidview") |
||||
|
## [1] '0.1.0' |
||||
|
``` |
||||
|
|
||||
|
``` r |
||||
|
library(cdccovidview) |
||||
|
library(hrbrthemes) |
||||
|
library(tidyverse) |
||||
|
|
||||
|
hosp <- laboratory_confirmed_hospitalizations() |
||||
|
|
||||
|
c( |
||||
|
"0-4 yr", "5-17 yr", "18-49 yr", "50-64 yr", "65+ yr", "65-74 yr", "75-84 yr", "85+" |
||||
|
) -> age_f |
||||
|
|
||||
|
mutate(hosp, start = mmwr_week_to_date(mmwr_year, mmwr_week)) %>% |
||||
|
filter(!is.na(weekly_rate)) %>% |
||||
|
filter(catchment == "Entire Network") %>% |
||||
|
select(start, network, age_category, weekly_rate) %>% |
||||
|
filter(age_category != "Overall") %>% |
||||
|
mutate(age_category = factor(age_category, levels = age_f)) %>% |
||||
|
ggplot() + |
||||
|
geom_line( |
||||
|
aes(start, weekly_rate) |
||||
|
) + |
||||
|
scale_x_date( |
||||
|
date_breaks = "2 weeks", date_labels = "%b\n%d" |
||||
|
) + |
||||
|
facet_grid(network~age_category) + |
||||
|
labs( |
||||
|
x = NULL, y = "Rates per 100,000 pop", |
||||
|
title = "COVID-NET Weekly Rates by Network and Age Group", |
||||
|
caption = sprintf("Source: COVID-NET: COVID-19-Associated Hospitalization Surveillance Network, Centers for Disease Control and Prevention.\n<https://gis.cdc.gov/grasp/COVIDNet/COVID19_3.html>; Accessed on %s", Sys.Date()) |
||||
|
) + |
||||
|
theme_ipsum_es(grid="XY") |
||||
|
``` |
||||
|
|
||||
|
<img src="man/figures/README-ex-01-1.png" width="960" /> |
||||
|
|
||||
|
## 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 | |
||||
|
|
||||
|
## Code of Conduct |
||||
|
|
||||
|
Please note that this project is released with a Contributor Code of |
||||
|
Conduct. By participating in this project you agree to abide by its |
||||
|
terms. |
@ -0,0 +1,16 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/about.R |
||||
|
\name{about} |
||||
|
\alias{about} |
||||
|
\title{Display information about the data source} |
||||
|
\usage{ |
||||
|
about(display = c("html", "text")) |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{display}{if \code{html} (the default) a formatted version of |
||||
|
the description is provided, otherwise a plaintext version |
||||
|
will be provided.} |
||||
|
} |
||||
|
\description{ |
||||
|
Display information about the data source |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/age-groups.R |
||||
|
\name{age_groups} |
||||
|
\alias{age_groups} |
||||
|
\title{Return age groups used in the surveillance} |
||||
|
\usage{ |
||||
|
age_groups() |
||||
|
} |
||||
|
\value{ |
||||
|
character vector |
||||
|
} |
||||
|
\description{ |
||||
|
Return age groups used in the surveillance |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/seasons.R |
||||
|
\name{available_seasons} |
||||
|
\alias{available_seasons} |
||||
|
\title{Show available seasons} |
||||
|
\usage{ |
||||
|
available_seasons() |
||||
|
} |
||||
|
\value{ |
||||
|
data frame |
||||
|
} |
||||
|
\description{ |
||||
|
Show available seasons |
||||
|
} |
After Width: | Height: | Size: 64 KiB |
@ -0,0 +1,11 @@ |
|||||
|
% 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,15 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/laboratory-confirmed-hospitalizations.R |
||||
|
\name{laboratory_confirmed_hospitalizations} |
||||
|
\alias{laboratory_confirmed_hospitalizations} |
||||
|
\title{Retrieve Laboratory-Confirmed COVID-19-Associated Hospitalizations} |
||||
|
\usage{ |
||||
|
laboratory_confirmed_hospitalizations() |
||||
|
} |
||||
|
\value{ |
||||
|
data frame |
||||
|
} |
||||
|
\description{ |
||||
|
This function grabs all data for all networks, catchments, seasons, and ages. |
||||
|
In the future there will be ways of selecting just the desired target areas. |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/mmwr-utils.R |
||||
|
\name{mmwr_week} |
||||
|
\alias{mmwr_week} |
||||
|
\title{Convert a Date to an MMWR day+week+year} |
||||
|
\usage{ |
||||
|
mmwr_week(x) |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{x}{a vector of \code{Date} objects or a character vector in \code{YYYY-mm-dd} format.} |
||||
|
} |
||||
|
\value{ |
||||
|
data frame (tibble) |
||||
|
} |
||||
|
\description{ |
||||
|
This is a reformat and re-export of a function in the \code{MMWRweek} package. |
||||
|
It provides a snake case version of its counterpart, produces a \code{tibble} |
||||
|
} |
||||
|
\examples{ |
||||
|
mwk <- mmwr_week(Sys.Date()) |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/mmwr-utils.R |
||||
|
\name{mmwr_week_to_date} |
||||
|
\alias{mmwr_week_to_date} |
||||
|
\title{Convert an MMWR year+week or year+week+day to a Date object} |
||||
|
\usage{ |
||||
|
mmwr_week_to_date(year, week, day = NULL) |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{year, week, day}{Year, week and month vectors. All must be the same length |
||||
|
unless \code{day} is \code{NULL}.} |
||||
|
} |
||||
|
\value{ |
||||
|
vector of \code{Date} objects |
||||
|
} |
||||
|
\description{ |
||||
|
This is a reformat and re-export of a function in the \code{MMWRweek} package. |
||||
|
It provides a snake case version of its counterpart and produces a vector |
||||
|
of \code{Date} objects that corresponds to the input MMWR year+week or year+week+day |
||||
|
vectors. This also adds some parameter checking and cleanup to avoid exceptions. |
||||
|
} |
||||
|
\examples{ |
||||
|
mwd <- mmwr_week_to_date(2016,10,3) |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/mmwr-utils.R |
||||
|
\name{mmwr_weekday} |
||||
|
\alias{mmwr_weekday} |
||||
|
\title{Convert a Date to an MMWR weekday} |
||||
|
\usage{ |
||||
|
mmwr_weekday(x, abbr = FALSE) |
||||
|
} |
||||
|
\arguments{ |
||||
|
\item{x}{a vector of \code{Date} objects or a character vector in \code{YYYY-mm-dd} format.} |
||||
|
|
||||
|
\item{abbr}{(logical) if \code{TRUE}, return abbreviated weekday names, otherwise full |
||||
|
weekday names (see Note).} |
||||
|
} |
||||
|
\value{ |
||||
|
ordered factor |
||||
|
} |
||||
|
\description{ |
||||
|
This is a reformat and re-export of a function in the \code{MMWRweek} package. |
||||
|
It provides a snake case version of its counterpart, produces a \code{factor} of |
||||
|
weekday names (Sunday-Saturday). |
||||
|
} |
||||
|
\note{ |
||||
|
Weekday names are explicitly mapped to "Sunday-Saturday" or "Sun-Sat" and |
||||
|
do not change with your locale. |
||||
|
} |
||||
|
\examples{ |
||||
|
mwday <- mmwr_weekday(Sys.Date()) |
||||
|
} |
@ -0,0 +1,22 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/mmwr-utils.R |
||||
|
\docType{data} |
||||
|
\name{mmwrid_map} |
||||
|
\alias{mmwrid_map} |
||||
|
\title{MMWR ID to Calendar Mappings} |
||||
|
\format{ |
||||
|
A data frame with 4,592 rows and 4 columns |
||||
|
} |
||||
|
\description{ |
||||
|
The CDC uses a unique "Morbidity and Mortality Weekly Report" identifier |
||||
|
for each week that starts at 1 (Ref: < https://www.cdc.gov/mmwr/preview/mmwrhtml/su6004a9.htm>). |
||||
|
This data frame consists of 4 columns: |
||||
|
\itemize{ |
||||
|
\item \code{wk_start}: Start date (Sunday) for the week (\code{Date}) |
||||
|
\item \code{wk_end}: End date (Saturday) for the week (\code{Date}) |
||||
|
\item \code{year_wk_num}: The week of the calendar year |
||||
|
\item \code{mmwrid}: The unique MMWR identifier |
||||
|
These can be "left-joined" to data provided from the CDC to perform MMWR identifier |
||||
|
to date mappings. |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
% 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 |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
% Generated by roxygen2: do not edit by hand |
||||
|
% Please edit documentation in R/surveillance-area-info.R |
||||
|
\name{surveillance_areas} |
||||
|
\alias{surveillance_areas} |
||||
|
\title{Show network & network catchments} |
||||
|
\usage{ |
||||
|
surveillance_areas() |
||||
|
} |
||||
|
\value{ |
||||
|
data frame |
||||
|
} |
||||
|
\description{ |
||||
|
Show network & network catchments |
||||
|
} |
Loading…
Reference in new issue