diff --git a/DESCRIPTION b/DESCRIPTION index b413205..7e46555 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,16 +1,16 @@ Package: cdcfluview Type: Package Title: Retrieve U.S. Flu Season Data from the CDC FluView Portal -Version: 0.4.1.9000 -Date: 2015-08-09 -Author: Bob Rudis (@hrbrmstr) -Maintainer: Bob Rudis +Version: 0.5.0 +Date: 2016-09-25 +Author: Bob Rudis (bob@rud.is) +Maintainer: Bob Rudis Description: The U.S. Centers for Disease Control (CDC) maintains a portal for - accessing state, regional and national influenza statistics. The Flash - interface makes it difficult and time-consuming to select and retrieve - influenza data. This package provides functions to access the data provided - by the portal's underlying API. + accessing state, regional and national influenza statistics as well as + Mortality Surveillance Data. The Flash interface makes it difficult and + time-consuming to select and retrieve influenza data. This package + provides functions to access the data provided by the portal's underlying API. URL: http://github.com/hrbrmstr/cdcfluview BugReports: https://github.com/hrbrmstr/cdcfluview/issues License: MIT + file LICENSE @@ -19,9 +19,11 @@ Suggests: testthat Imports: httr (>= 0.3.0), - pbapply, xml2, dplyr, - utils + utils, + purrr, + readr Depends: - R (>= 3.0.0) + R (>= 3.2.0) +RoxygenNote: 5.0.1 diff --git a/NAMESPACE b/NAMESPACE index 27a10a4..ba2a80b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,10 +1,17 @@ -# Generated by roxygen2 (4.1.1): do not edit by hand +# Generated by roxygen2: do not edit by hand export(get_flu_data) +export(get_mortality_surveillance_data) export(get_state_data) export(get_weekly_flu_report) import(dplyr) import(httr) -import(pbapply) import(utils) import(xml2) +importFrom(purrr,discard) +importFrom(purrr,keep) +importFrom(purrr,map) +importFrom(purrr,map_chr) +importFrom(purrr,map_df) +importFrom(purrr,map_lgl) +importFrom(readr,read_csv) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..392cb30 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,8 @@ +# cdcfluview 0.5.0 + +* Fixed issue with WHO data format change +* Added Mortality Surveillance Data retrieval function +* Switched to readr::read_csv() and since it handles column names + better this will break your scripts until you use the new + column names. + diff --git a/R/cdcfluview-package.R b/R/cdcfluview-package.R index cfb78d8..c1b4835 100644 --- a/R/cdcfluview-package.R +++ b/R/cdcfluview-package.R @@ -2,13 +2,15 @@ #' #' The U.S. Centers for Disease Control (CDC) maintains a portal #' \code{http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html} for -#' accessing state, regional and national influenza statistics. The Flash -#' interface makes it difficult and time-consuming to select and retrieve -#' influenza data. This package provides functions to access the data provided -#' by portal's underlying API. +#' accessing state, regional and national influenza statistics as well as +#' Mortality Surveillance Data. The Flash interface makes it difficult +#' and time-consuming to select and retrieve influenza data. This package +#' provides functions to access the data provided by portal's underlying API. #' #' @name cdcfluview #' @docType package -#' @author Bob Rudis (@@hrbrmstr) -#' @import httr pbapply xml2 dplyr utils +#' @author Bob Rudis (bob@@rud.is) +#' @import httr xml2 dplyr utils +#' @importFrom purrr map map_df map_chr map_lgl discard keep +#' @importFrom readr read_csv NULL diff --git a/R/get_flu_data.r b/R/get_flu_data.r index 461c6da..78a1e8b 100644 --- a/R/get_flu_data.r +++ b/R/get_flu_data.r @@ -51,8 +51,8 @@ get_flu_data <- function(region="hhs", sub_region=1:10, if ((region=="census") && !all(sub_region %in% 1:19)) stop("Error: sub_region values must fall between 1:10 when region is 'census'") - if (!all(data_source %in% c("who", "ilinet"))) - stop("Error: data_source must be either 'who', 'ilinet' or both") + if (!all(data_source %in% c("who", "ilinet", "all"))) + stop("Error: data_source must be either 'who', 'ilinet', 'all' or c('who', 'ilinet')") if (any(years < 1997)) stop("Error: years should be > 1997") @@ -62,6 +62,9 @@ get_flu_data <- function(region="hhs", sub_region=1:10, years <- years - 1960 reg <- as.numeric(c("hhs"=1, "census"=2, "national"=3)[[region]]) + + if ("all" %in% data_source) data_source <- c("who", "ilinet") + data_source <- gsub("who", "WHO_NREVSS", data_source) data_source <- gsub("ilinet", "ILINet", data_source) @@ -72,9 +75,9 @@ get_flu_data <- function(region="hhs", sub_region=1:10, out_file <- tempfile(fileext=".zip") - tmp <- POST("http://gis.cdc.gov/grasp/fluview/FluViewPhase2CustomDownload.ashx", - body=params, - write_disk(out_file)) + tmp <- httr::POST("http://gis.cdc.gov/grasp/fluview/FluViewPhase2CustomDownload.ashx", + body=params, + write_disk(out_file)) stop_for_status(tmp) @@ -85,10 +88,12 @@ get_flu_data <- function(region="hhs", sub_region=1:10, files <- unzip(out_file, exdir=out_dir, overwrite=TRUE) - file_list <- pblapply(files, function(x) { - ct <- ifelse(grepl("who", x, ignore.case=TRUE), 0, 1) - read.csv(x, header=TRUE, skip=ct, stringsAsFactors=FALSE) - }) + pb <- dplyr::progress_estimated(length(files)) + purrr::map(files, function(x) { + pb$tick()$print() + ct <- ifelse(grepl("who", x, ignore.case=TRUE), 1, 1) + suppressMessages(readr::read_csv(x, skip=ct)) + }) -> file_list names(file_list) <- substr(basename(files), 1, 3) diff --git a/R/get_state_data.r b/R/get_state_data.r index 1d6c014..8ee7156 100644 --- a/R/get_state_data.r +++ b/R/get_state_data.r @@ -19,7 +19,7 @@ #' servers to crunch the data. Wrap the function call in \code{httr::with_verbose} #' if you would like to see what's going on. #' @examples \dontrun{ -#' get_state_dat(2014) +#' get_state_data(2014) #' get_state_data(c(2013, 2014)) #' get_state_data(2010:2014) #' httr::with_verbose(get_state_data(2009:2015)) @@ -39,7 +39,7 @@ get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) { DataMode="STATE", SeasonsList=paste0(years, collapse=",")) - tmp <- POST("http://gis.cdc.gov/grasp/fluview/FluViewPhase1CustomDownload.ashx", + tmp <- httr::POST("http://gis.cdc.gov/grasp/fluview/FluViewPhase1CustomDownload.ashx", body=params, write_disk(out_file)) @@ -52,7 +52,8 @@ get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) { files <- unzip(out_file, exdir=out_dir, overwrite=TRUE) - out <- read.csv(files, header=TRUE, stringsAsFactors=FALSE) + out <- read.csv(files, header=TRUE, stringsAsFactors=FALSE) + # out <- readr::read_csv(files, col_types="cccccic") class(out) <- c("cdcstatedata", class(out)) diff --git a/R/get_weekly_flu_report.r b/R/get_weekly_flu_report.r index e7e2d2b..45e0c16 100644 --- a/R/get_weekly_flu_report.r +++ b/R/get_weekly_flu_report.r @@ -27,12 +27,15 @@ get_weekly_flu_report <- function() { # for each period extract the state information and # shove it all into a data frame - bind_rows(pblapply(periods, function(period) { + pb <- progress_estimated(length(periods)) + purrr::map_df(periods, function(period) { + + pb$tick()$print() tp <- sprintf("//timeperiod[@number='%s' and @year='%s']", period["number"], period["year"]) - weeks <- xml_find_one(doc, tp) + weeks <- xml_find_first(doc, tp) kids <- xml_children(weeks) abbrev <- xml_text(xml_find_all(kids, "abbrev"), TRUE) @@ -46,7 +49,7 @@ get_weekly_flu_report <- function() { label=label, subtitle=period["subtitle"]) - })) -> out + }) -> out class(out) <- c("cdcweeklyreport", class(out)) diff --git a/R/mortalty.r b/R/mortalty.r new file mode 100644 index 0000000..160ef51 --- /dev/null +++ b/R/mortalty.r @@ -0,0 +1,78 @@ +#' Mortality Surveillance Data from the National Center for Health Statistics +#' +#' The National Center for Health Statistics (NCHS) collects and disseminates the Nation's +#' official vital statistics. These statistics are based on data provided to NCHS through +#' contracts with the vital registration systems operated in the various jurisdictions +#' legally responsible for the registration of deaths (i.e., death certificates) and other +#' vital events. These data have previously only been released as annual final data files +#' 12 months or more after the end of the data year. Recent NCHS efforts to improve the +#' timeliness of jurisdiction reporting and modernize the national vital statistics +#' infrastructure have created a system capable of supporting near real-time surveillance. +#' Capitalizing on these new capabilities, NCHS and CDC’s Influenza Division have +#' partnered to pilot the use of NCHS mortality surveillance data for Pneumonia and +#' Influenza (P&I) mortality surveillance. +#' +#' NCHS mortality surveillance data are presented by the week the death occurred. +#' Nationally P&I percentages are released two weeks after the week of death to allow for +#' collection of enough data to produce a stable P&I percentage at the national level. +#' Collection of complete data is not expected, and reliable P&I ratios are not expected +#' at the region and state level within this two week period. State and Region level +#' counts will be released only after 20% of the expected number of deaths are reported +#' through the system. +#' +#' @references \url{http://www.cdc.gov/flu/weekly/nchs.htm} +#' @return a list of \code{tbl_df}s +#' @export +#' @examples \dontrun{ +#' get_mortality_surveillance_data() +#' } +get_mortality_surveillance_data <- function() { + + pg <- read_html("http://www.cdc.gov/flu/weekly/nchs.htm") + + PREFIX <- "http://www.cdc.gov" + + xml_find_all(pg, ".//select[@id='State']/option[contains(@value, 'csv') and + contains(@value, 'State_')]") %>% + xml_attr("value") %>% + sprintf("%s%s", PREFIX, .) -> targets + + pb <- progress_estimated(length(targets)) + map_df(targets, function(x) { + pb$tick()$print() + suppressMessages(read_csv(URLencode(x), col_types="ciidii")) + }) -> influenza_mortality_by_state + + + xml_find_all(pg, ".//select[@id='Regional Data']/ + option[contains(@value, 'csv') and + not(contains(@value, 'Week_'))]") %>% + xml_attr("value") %>% + sprintf("%s%s", PREFIX, .) -> targets + + pb <- progress_estimated(length(targets)) + map_df(targets, function(x) { + pb$tick()$print() + suppressMessages(read_csv(URLencode(x), col_types="ciidii")) + }) -> influenza_mortality_by_region + + + xml_find_all(pg, ".//select[@id='Regional Data']/ + option[contains(@value, 'csv') and + contains(@value, 'Week_')]") %>% + xml_attr("value") %>% + sprintf("%s%s", PREFIX, .) -> targets + + pb <- progress_estimated(length(targets)) + map_df(targets, function(x) { + pb$tick()$print() + suppressMessages(read_csv(URLencode(x), col_types="ciidii")) + }) -> influenza_mortality_by_week + + list( + by_state=influenza_mortality_by_state, + by_region=influenza_mortality_by_region, + by_week=influenza_mortality_by_week + ) + +} diff --git a/R/zzz.r b/R/zzz.r new file mode 100644 index 0000000..c53ae57 --- /dev/null +++ b/R/zzz.r @@ -0,0 +1,10 @@ +.onAttach <- function(...) { + + if (!interactive()) return() + + packageStartupMessage(paste0("cdcfluview is under *active* development. ", + "There are *breaking changes*. ", + "See https://github.com/hrbrmstr/cdcfluview for info/news.")) + +} + diff --git a/README.Rmd b/README.Rmd index 9cd553d..e79cfb0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -1,10 +1,5 @@ --- -title: "README" -author: "Bob Rudis" -date: August 9, 2015 -output: - md_document: - variant: markdown_github +output: rmarkdown::github_document --- ```{r, echo=FALSE} @@ -19,7 +14,7 @@ knitr::opts_chunk$set( ``` ### :mask: cdcfluview - Retrieve U.S. Flu Season Data from the CDC FluView Portal -[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cdcfluview)](http://cran.r-project.org/web/packages/cdcfluview) +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cdcfluview)](https://cran.r-project.org/package=cdcfluview) **NOTE** If there's a particular data set from http://www.cdc.gov/flu/weekly/fluviewinteractive.htm that you want and that isn't in the package, please file it as an issue and be as specific as you can (screen shot if possible). @@ -32,6 +27,7 @@ The following functions are implemented: - `get_flu_data`: Retrieves state, regional or national influenza statistics from the CDC - `get_state_data`: Retrieves state/territory-level influenza statistics from the CDC - `get_weekly_flu_report`: Retrieves (high-level) weekly influenza surveillance report from the CDC +- `get_mortality_surveillance_data` : (fairly self explanatory but also pretty new to the pkg and uses data from: http://www.cdc.gov/flu/weekly/nchs.htm The following data sets are included: @@ -40,6 +36,7 @@ The following data sets are included: ### News +- See NEWS - Version 0.4.0 - [CRAN release](http://cran.r-project.org/web/packages/cdcfluview) - Version 0.4.0.999 released : another fix for the CDC API (for region parameter); added data files for HHS/Census region lookups; added weekly high-level flu report retrieval - Version 0.3 released : fix for the CDC API (it changed how year & region params are encoded in the request) @@ -61,11 +58,11 @@ options(width=120) ### Usage -```{r} -suppressPackageStartupMessages(library(cdcfluview)) -suppressPackageStartupMessages(library(ggplot2)) -suppressPackageStartupMessages(library(dplyr)) -suppressPackageStartupMessages(library(statebins)) +```{r message=FALSE} +library(cdcfluview) +library(ggplot2) +library(dplyr) +library(statebins) # current verison packageVersion("cdcfluview") @@ -76,7 +73,7 @@ glimpse(flu) state_flu <- get_state_data(years=2014) glimpse(state_flu) -gg <- ggplot(flu, aes(x=WEEK, y=X..WEIGHTED.ILI, group=REGION)) +gg <- ggplot(flu, aes(x=WEEK, y=`% WEIGHTED ILI`, group=REGION)) gg <- gg + geom_line() gg <- gg + facet_wrap(~REGION, ncol=2) gg <- gg + theme_bw() @@ -86,7 +83,7 @@ gg <- gg + theme_bw() gg ``` -```{r warning=FALSE, error=FALSE, message=FALSE} +```{r eval=FALSE, include=FALSE, warning=FALSE, error=FALSE, message=FALSE} dat <- get_flu_data(region="hhs", sub_region=1:10, data_source="ilinet", @@ -113,13 +110,13 @@ curr_week <- tail(dat, 1)$season_week gg <- ggplot() gg <- gg + geom_point(data=prev_years, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), - color="#969696", size=1, alpa=0.25) + aes(x=season_week, y=`% WEIGHTED ILI`, group=season), + color="#969696", size=1, alpha=0.25) gg <- gg + geom_point(data=curr_year, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), + aes(x=season_week, y=`% WEIGHTED ILI`, group=season), color="red", size=1.25, alpha=1) gg <- gg + geom_line(data=curr_year, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), + aes(x=season_week, y=`% WEIGHTED ILI`, group=season), size=1.25, color="#d7301f") gg <- gg + geom_vline(xintercept=curr_week, color="#d7301f", size=0.5, linetype="dashed", alpha=0.5) gg <- gg + facet_wrap(~REGION, ncol=3) @@ -136,7 +133,7 @@ gg <- gg + theme(axis.text.x=element_blank()) gg ``` -```{r} +```{r message=FALSE} gg_s <- state_flu %>% filter(WEEKEND=="Jan-03-2015") %>% select(state=STATENAME, value=ACTIVITY.LEVEL) %>% @@ -154,9 +151,9 @@ gg_s ### Test Results -```{r} -suppressPackageStartupMessages(library(cdcfluview)) -suppressPackageStartupMessages(library(testthat)) +```{r message=FALSE} +library(cdcfluview) +library(testthat) date() diff --git a/README.md b/README.md index 7044206..3827596 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ + ### :mask: cdcfluview - Retrieve U.S. Flu Season Data from the CDC FluView Portal -[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/cdcfluview)](http://cran.r-project.org/web/packages/cdcfluview) +[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/cdcfluview)](https://cran.r-project.org/package=cdcfluview) **NOTE** If there's a particular data set from that you want and that isn't in the package, please file it as an issue and be as specific as you can (screen shot if possible). @@ -13,6 +14,7 @@ The following functions are implemented: - `get_flu_data`: Retrieves state, regional or national influenza statistics from the CDC - `get_state_data`: Retrieves state/territory-level influenza statistics from the CDC - `get_weekly_flu_report`: Retrieves (high-level) weekly influenza surveillance report from the CDC +- `get_mortality_surveillance_data` : (fairly self explanatory but also pretty new to the pkg and uses data from: The following data sets are included: @@ -21,6 +23,7 @@ The following data sets are included: ### News +- See NEWS - Version 0.4.0 - [CRAN release](http://cran.r-project.org/web/packages/cdcfluview) - Version 0.4.0.999 released : another fix for the CDC API (for region parameter); added data files for HHS/Census region lookups; added weekly high-level flu report retrieval - Version 0.3 released : fix for the CDC API (it changed how year & region params are encoded in the request) @@ -39,103 +42,57 @@ devtools::install_github("hrbrmstr/cdcfluview") ### Usage ``` r -suppressPackageStartupMessages(library(cdcfluview)) -suppressPackageStartupMessages(library(ggplot2)) -suppressPackageStartupMessages(library(dplyr)) -suppressPackageStartupMessages(library(statebins)) +library(cdcfluview) +library(ggplot2) +library(dplyr) +library(statebins) # current verison packageVersion("cdcfluview") -#> [1] '0.4.1.9000' +#> [1] '0.5.0' flu <- get_flu_data("hhs", sub_region=1:10, "ilinet", years=2014) glimpse(flu) -#> Observations: 440 -#> Variables: -#> $ REGION.TYPE (chr) "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions",... -#> $ REGION (chr) "Region 1", "Region 2", "Region 3", "Region 4", "Region 5", "Region 6", "Region 7", "Regi... -#> $ YEAR (int) 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,... -#> $ WEEK (int) 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 42, 42, 4... -#> $ ILITOTAL (int) 352, 2254, 1696, 1182, 1083, 1844, 220, 348, 1329, 61, 386, 2129, 1747, 1517, 1117, 2165,... -#> $ TOTAL.PATIENTS (int) 51688, 137157, 129302, 130419, 107261, 103975, 50272, 37014, 88421, 11172, 51169, 132513,... -#> $ NUM..OF.PROVIDERS (int) 147, 285, 245, 305, 267, 241, 84, 117, 237, 55, 151, 274, 241, 310, 277, 250, 84, 114, 24... -#> $ X..WEIGHTED.ILI (dbl) 0.8306102, 1.7759176, 1.1477759, 0.8167958, 0.7370374, 1.8252298, 0.6970221, 0.6731439, 1... -#> $ X.UNWEIGHTED.ILI (dbl) 0.6810091, 1.6433722, 1.3116580, 0.9063097, 1.0096867, 1.7735032, 0.4376194, 0.9401848, 1... -#> $ AGE.0.4 (int) 101, 869, 395, 333, 358, 465, 50, 82, 310, 22, 109, 837, 404, 356, 339, 560, 57, 58, 335,... -#> $ AGE.5.24 (int) 185, 757, 629, 536, 400, 711, 98, 152, 577, 30, 199, 677, 670, 774, 443, 809, 124, 146, 5... -#> $ AGE.25.64 (lgl) NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... -#> $ AGE.25.49 (int) 44, 363, 455, 187, 181, 469, 43, 87, 220, 7, 37, 349, 466, 249, 182, 509, 56, 87, 225, 20... -#> $ AGE.50.64 (int) 13, 157, 127, 80, 80, 121, 15, 19, 110, 1, 24, 151, 132, 74, 105, 187, 18, 23, 118, 10, 2... -#> $ AGE.65 (int) 9, 108, 90, 46, 64, 78, 14, 8, 112, 1, 17, 115, 75, 64, 48, 100, 14, 12, 103, 3, 9, 110, ... +#> Observations: 530 +#> Variables: 15 +#> $ REGION TYPE "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions", "HHS Regions",... +#> $ REGION "Region 1", "Region 2", "Region 3", "Region 4", "Region 5", "Region 6", "Region 7", "Regi... +#> $ YEAR 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014, 2014,... +#> $ WEEK 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 42, 42, 4... +#> $ % WEIGHTED ILI 0.830610, 1.775920, 1.147780, 0.816796, 0.737037, 1.828510, 0.697022, 0.673507, 1.781290,... +#> $ %UNWEIGHTED ILI 0.681009, 1.643370, 1.311660, 0.906310, 1.009690, 1.775430, 0.437619, 0.930417, 1.497090,... +#> $ AGE 0-4 101, 869, 395, 333, 358, 465, 50, 82, 310, 22, 109, 884, 404, 355, 339, 560, 57, 58, 335,... +#> $ AGE 25-49 44, 363, 455, 187, 181, 469, 43, 87, 220, 7, 37, 385, 466, 247, 182, 504, 56, 87, 225, 20... +#> $ AGE 25-64 NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N... +#> $ AGE 5-24 185, 757, 629, 536, 400, 711, 98, 155, 577, 30, 199, 704, 670, 772, 443, 809, 124, 148, 5... +#> $ AGE 50-64 13, 157, 127, 80, 80, 123, 15, 19, 110, 1, 24, 176, 132, 74, 105, 186, 18, 23, 118, 10, 2... +#> $ AGE 65 9, 108, 90, 46, 64, 78, 14, 8, 112, 1, 17, 127, 75, 64, 48, 100, 14, 12, 103, 3, 9, 114, ... +#> $ ILITOTAL 352, 2254, 1696, 1182, 1083, 1846, 220, 351, 1329, 61, 386, 2276, 1747, 1512, 1117, 2159,... +#> $ NUM. OF PROVIDERS 147, 285, 244, 305, 267, 241, 84, 120, 240, 55, 151, 275, 241, 311, 277, 250, 84, 116, 24... +#> $ TOTAL PATIENTS 51688, 137157, 129302, 130419, 107261, 103975, 50272, 37725, 88772, 11172, 51169, 134995,... state_flu <- get_state_data(years=2014) glimpse(state_flu) -#> Observations: 2809 -#> Variables: -#> $ STATENAME (chr) "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama"... -#> $ URL (chr) "http://adph.org/influenza/", "http://adph.org/influenza/", "http://adph.org/influenza... -#> $ WEBSITE (chr) "Influenza Surveillance", "Influenza Surveillance", "Influenza Surveillance", "Influen... -#> $ ACTIVITY.LEVEL (chr) "Level 1", "Level 1", "Level 1", "Level 1", "Level 1", "Level 1", "Level 5", "Level 10... -#> $ ACTIVITY.LEVEL.LABEL (chr) "Minimal", "Minimal", "Minimal", "Minimal", "Minimal", "Minimal", "Low", "High", "High... -#> $ WEEKEND (chr) "Oct-04-2014", "Oct-11-2014", "Oct-18-2014", "Oct-25-2014", "Nov-01-2014", "Nov-08-201... -#> $ WEEK (int) 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,... -#> $ SEASON (chr) "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15"... - -gg <- ggplot(flu, aes(x=WEEK, y=X..WEIGHTED.ILI, group=REGION)) +#> Observations: 2,809 +#> Variables: 8 +#> $ STATENAME "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama", "Alabama"... +#> $ URL "http://adph.org/influenza/", "http://adph.org/influenza/", "http://adph.org/influenza... +#> $ WEBSITE "Influenza Surveillance", "Influenza Surveillance", "Influenza Surveillance", "Influen... +#> $ ACTIVITY.LEVEL "Level 1", "Level 1", "Level 1", "Level 1", "Level 1", "Level 1", "Level 5", "Level 10... +#> $ ACTIVITY.LEVEL.LABEL "Minimal", "Minimal", "Minimal", "Minimal", "Minimal", "Minimal", "Low", "High", "High... +#> $ WEEKEND "Oct-04-2014", "Oct-11-2014", "Oct-18-2014", "Oct-25-2014", "Nov-01-2014", "Nov-08-201... +#> $ WEEK 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,... +#> $ SEASON "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15", "2014-15"... + +gg <- ggplot(flu, aes(x=WEEK, y=`% WEIGHTED ILI`, group=REGION)) gg <- gg + geom_line() gg <- gg + facet_wrap(~REGION, ncol=2) gg <- gg + theme_bw() ``` - - -``` r -dat <- get_flu_data(region="hhs", - sub_region=1:10, - data_source="ilinet", - years=2000:2014) - -dat %>% - mutate(REGION=factor(REGION, - levels=unique(REGION), - labels=c("Boston", "New York", - "Philadelphia", "Atlanta", - "Chicago", "Dallas", - "Kansas City", "Denver", - "San Francisco", "Seattle"), - ordered=TRUE)) %>% - mutate(season_week=ifelse(WEEK>=40, WEEK-40, WEEK), - season=ifelse(WEEK<40, - sprintf("%d-%d", YEAR-1, YEAR), - sprintf("%d-%d", YEAR, YEAR+1))) -> dat - -prev_years <- dat %>% filter(season != "2014-2015") -curr_year <- dat %>% filter(season == "2014-2015") - -curr_week <- tail(dat, 1)$season_week - -gg <- ggplot() -gg <- gg + geom_point(data=prev_years, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), - color="#969696", size=1, alpa=0.25) -gg <- gg + geom_point(data=curr_year, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), - color="red", size=1.25, alpha=1) -gg <- gg + geom_line(data=curr_year, - aes(x=season_week, y=X..WEIGHTED.ILI, group=season), - size=1.25, color="#d7301f") -gg <- gg + geom_vline(xintercept=curr_week, color="#d7301f", size=0.5, linetype="dashed", alpha=0.5) -gg <- gg + facet_wrap(~REGION, ncol=3) -gg <- gg + labs(x=NULL, y="Weighted ILI Index", - title="ILINet - 1999-2015 year weighted flu index history by CDC region\nWeek Ending Jan 3, 2015 (Red == 2014-2015 season)\n") -gg <- gg + theme_bw() -gg <- gg + theme(panel.grid=element_blank()) -gg <- gg + theme(strip.background=element_blank()) -gg <- gg + theme(axis.ticks.x=element_blank()) -gg <- gg + theme(axis.text.x=element_blank()) -``` + - + ``` r gg_s <- state_flu %>% @@ -149,20 +106,20 @@ gg_s <- state_flu %>% ggtitle("CDC State FluView (2015-01-03)") ``` - + ### Test Results ``` r -suppressPackageStartupMessages(library(cdcfluview)) -suppressPackageStartupMessages(library(testthat)) +library(cdcfluview) +library(testthat) date() -#> [1] "Sun Aug 9 13:13:33 2015" +#> [1] "Mon Sep 26 01:39:06 2016" test_dir("tests/") #> testthat results ======================================================================================================== #> OK: 0 SKIPPED: 0 FAILED: 0 #> -#> DONE +#> DONE =================================================================================================================== ``` diff --git a/README_files/README-unnamed-chunk-5-1.png b/README_files/README-unnamed-chunk-5-1.png index 0144935..0e692dd 100644 Binary files a/README_files/README-unnamed-chunk-5-1.png and b/README_files/README-unnamed-chunk-5-1.png differ diff --git a/README_files/README-unnamed-chunk-7-1.png b/README_files/README-unnamed-chunk-7-1.png index c1c976d..0e692dd 100644 Binary files a/README_files/README-unnamed-chunk-7-1.png and b/README_files/README-unnamed-chunk-7-1.png differ diff --git a/README_files/README-unnamed-chunk-9-1.png b/README_files/README-unnamed-chunk-9-1.png index cc722af..d6bfeda 100644 Binary files a/README_files/README-unnamed-chunk-9-1.png and b/README_files/README-unnamed-chunk-9-1.png differ diff --git a/cdcfluview.Rproj b/cdcfluview.Rproj index 518e5c8..9c0079b 100644 --- a/cdcfluview.Rproj +++ b/cdcfluview.Rproj @@ -1,8 +1,8 @@ Version: 1.0 -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: No EnableCodeIndexing: Yes UseSpacesForTab: Yes diff --git a/man/cdcfluview.Rd b/man/cdcfluview.Rd index 5276a44..657f37e 100644 --- a/man/cdcfluview.Rd +++ b/man/cdcfluview.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/cdcfluview-package.r \docType{package} \name{cdcfluview} @@ -8,12 +8,12 @@ \description{ The U.S. Centers for Disease Control (CDC) maintains a portal \code{http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html} for -accessing state, regional and national influenza statistics. The Flash -interface makes it difficult and time-consuming to select and retrieve -influenza data. This package provides functions to access the data provided -by portal's underlying API. +accessing state, regional and national influenza statistics as well as +Mortality Surveillance Data. The Flash interface makes it difficult +and time-consuming to select and retrieve influenza data. This package +provides functions to access the data provided by portal's underlying API. } \author{ -Bob Rudis (@hrbrmstr) +Bob Rudis (bob@rud.is) } diff --git a/man/census_regions.Rd b/man/census_regions.Rd index 7e491bc..6dc66c6 100644 --- a/man/census_regions.Rd +++ b/man/census_regions.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/datasets.r \docType{data} \name{census_regions} diff --git a/man/get_flu_data.Rd b/man/get_flu_data.Rd index 6757d93..298a4a3 100644 --- a/man/get_flu_data.Rd +++ b/man/get_flu_data.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_flu_data.r \name{get_flu_data} \alias{get_flu_data} diff --git a/man/get_mortality_surveillance_data.Rd b/man/get_mortality_surveillance_data.Rd new file mode 100644 index 0000000..2a8ff45 --- /dev/null +++ b/man/get_mortality_surveillance_data.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/mortalty.r +\name{get_mortality_surveillance_data} +\alias{get_mortality_surveillance_data} +\title{Mortality Surveillance Data from the National Center for Health Statistics} +\usage{ +get_mortality_surveillance_data() +} +\value{ +a list of \code{tbl_df}s +} +\description{ +The National Center for Health Statistics (NCHS) collects and disseminates the Nation's +official vital statistics. These statistics are based on data provided to NCHS through +contracts with the vital registration systems operated in the various jurisdictions +legally responsible for the registration of deaths (i.e., death certificates) and other +vital events. These data have previously only been released as annual final data files +12 months or more after the end of the data year. Recent NCHS efforts to improve the +timeliness of jurisdiction reporting and modernize the national vital statistics +infrastructure have created a system capable of supporting near real-time surveillance. +Capitalizing on these new capabilities, NCHS and CDC’s Influenza Division have +partnered to pilot the use of NCHS mortality surveillance data for Pneumonia and +Influenza (P&I) mortality surveillance. +} +\details{ +NCHS mortality surveillance data are presented by the week the death occurred. +Nationally P&I percentages are released two weeks after the week of death to allow for +collection of enough data to produce a stable P&I percentage at the national level. +Collection of complete data is not expected, and reliable P&I ratios are not expected +at the region and state level within this two week period. State and Region level +counts will be released only after 20% of the expected number of deaths are reported +through the system. +} +\examples{ +\dontrun{ +get_mortality_surveillance_data() +} +} +\references{ +\url{http://www.cdc.gov/flu/weekly/nchs.htm} +} + diff --git a/man/get_state_data.Rd b/man/get_state_data.Rd index d98ecc4..2a1f459 100644 --- a/man/get_state_data.Rd +++ b/man/get_state_data.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_state_data.r \name{get_state_data} \alias{get_state_data} @@ -32,7 +32,7 @@ There is often a noticeable delay when making the API request to the CDC. This } \examples{ \dontrun{ -get_state_dat(2014) +get_state_data(2014) get_state_data(c(2013, 2014)) get_state_data(2010:2014) httr::with_verbose(get_state_data(2009:2015)) diff --git a/man/get_weekly_flu_report.Rd b/man/get_weekly_flu_report.Rd index 0831f07..9188fb9 100644 --- a/man/get_weekly_flu_report.Rd +++ b/man/get_weekly_flu_report.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/get_weekly_flu_report.r \name{get_weekly_flu_report} \alias{get_weekly_flu_report} diff --git a/man/hhs_regions.Rd b/man/hhs_regions.Rd index 9761138..436d58d 100644 --- a/man/hhs_regions.Rd +++ b/man/hhs_regions.Rd @@ -1,4 +1,4 @@ -% Generated by roxygen2 (4.1.1): do not edit by hand +% Generated by roxygen2: do not edit by hand % Please edit documentation in R/datasets.r \docType{data} \name{hhs_regions}