Browse Source

fixed state data d/l & added tests+travis

tags/v0.5.2
boB Rudis 7 years ago
parent
commit
0df2fdf1e0
  1. 2
      .Rbuildignore
  2. 26
      .travis.yml
  3. 4
      DESCRIPTION
  4. 1
      NAMESPACE
  5. 1
      NEWS.md
  6. 1
      R/aaa.r
  7. 1
      R/cdcfluview-package.R
  8. 34
      R/get_state_data.r
  9. 1
      R/mortalty.r
  10. 2
      man/get_state_data.Rd
  11. 4
      tests/testthat/test-cdcfluview.R

2
.Rbuildignore

@ -6,4 +6,4 @@
^crunch/.* ^crunch/.*
^README_files/ ^README_files/
^README_files/.* ^README_files/.*
^README-.* ^README-.*

26
.travis.yml

@ -1,23 +1,5 @@
language: c # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
before_install: language: R
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh sudo: false
- chmod 755 ./travis-tool.sh cache: packages
- ./travis-tool.sh bootstrap
install:
- ./travis-tool.sh install_github plyr
- ./travis-tool.sh install_deps
script: ./travis-tool.sh run_tests
on_failure:
- ./travis-tool.sh dump_logs
branches:
except:
- /-expt$/
notifications:
email:
on_success: change
on_failure: change

4
DESCRIPTION

@ -5,6 +5,7 @@ Version: 0.5.1
Date: 2016-12-05 Date: 2016-12-05
Author: Bob Rudis (bob@rud.is) Author: Bob Rudis (bob@rud.is)
Maintainer: Bob Rudis <bob@rud.is> Maintainer: Bob Rudis <bob@rud.is>
Encoding: UTF-8
Description: The U.S. Centers for Disease Control (CDC) maintains a portal Description: The U.S. Centers for Disease Control (CDC) maintains a portal
<http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html> for <http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html> for
accessing state, regional and national influenza statistics as well as accessing state, regional and national influenza statistics as well as
@ -23,7 +24,8 @@ Imports:
dplyr, dplyr,
utils, utils,
purrr, purrr,
readr readr,
V8
Depends: Depends:
R (>= 3.2.0) R (>= 3.2.0)
RoxygenNote: 5.0.1 RoxygenNote: 5.0.1

1
NAMESPACE

@ -4,6 +4,7 @@ export(get_flu_data)
export(get_mortality_surveillance_data) export(get_mortality_surveillance_data)
export(get_state_data) export(get_state_data)
export(get_weekly_flu_report) export(get_weekly_flu_report)
import(V8)
import(dplyr) import(dplyr)
import(httr) import(httr)
import(utils) import(utils)

1
NEWS.md

@ -1,6 +1,7 @@
# cscfluview 0.5.1 # cscfluview 0.5.1
* Replaced `http` URLs with `https` as `http` ones no longer work (fixes #6) * Replaced `http` URLs with `https` as `http` ones no longer work (fixes #6)
* Fixed State data download (CDC changed the hidden API)
# cdcfluview 0.5.0 # cdcfluview 0.5.0

1
R/aaa.r

@ -0,0 +1 @@
utils::globalVariables(".")

1
R/cdcfluview-package.R

@ -13,4 +13,5 @@
#' @import httr xml2 dplyr utils #' @import httr xml2 dplyr utils
#' @importFrom purrr map map_df map_chr map_lgl discard keep #' @importFrom purrr map map_df map_chr map_lgl discard keep
#' @importFrom readr read_csv #' @importFrom readr read_csv
#' @import V8
NULL NULL

34
R/get_state_data.r

@ -10,7 +10,7 @@
#' #'
#' @param years a vector of years to retrieve data for (i.e. \code{2014} for CDC #' @param years a vector of years to retrieve data for (i.e. \code{2014} for CDC
#' flu season 2014-2015). Default value is the current year and all #' flu season 2014-2015). Default value is the current year and all
#' \code{years} values should be > \code{1997} #' \code{years} values should be >= \code{2008}
#' @return A \code{data.frame} of state-level data for the specified seasons #' @return A \code{data.frame} of state-level data for the specified seasons
#' (also classed as \code{cdcstatedata}) #' (also classed as \code{cdcstatedata})
#' @export #' @export
@ -26,34 +26,22 @@
#' } #' }
get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) { get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) {
if (any(years < 1997)) if (any(years < 2008))
stop("Error: years should be > 1997") stop("Error: years should be >= 2008")
years <- years - 1960 years <- c((years - 1960), 1)
years <- paste0(years, collapse=",")
out_file <- tempfile(fileext=".zip") tmp <- httr::GET(sprintf("https://gis.cdc.gov/grasp/fluView1/Phase1DownloadDataP/%s", years))
params <- list(EndMMWRID=0,
StartMMWRID=0,
QueryType=1,
DataMode="STATE",
SeasonsList=paste0(years, collapse=","))
tmp <- httr::POST("https://gis.cdc.gov/grasp/fluview/FluViewPhase1CustomDownload.ashx",
body=params,
write_disk(out_file))
stop_for_status(tmp) stop_for_status(tmp)
if (!(file.exists(out_file))) res <- httr::content(tmp, as="parsed")
stop("Error: cannot process downloaded data")
out_dir <- tempdir()
files <- unzip(out_file, exdir=out_dir, overwrite=TRUE)
out <- read.csv(files, header=TRUE, stringsAsFactors=FALSE) ctx <- v8()
# out <- readr::read_csv(files, col_types="cccccic") ctx$eval(JS(sprintf("var dat=%s;", res)))
res <- ctx$get("dat", flatten=FALSE)
out <- suppressMessages(readr::type_convert(res$datadownload))
class(out) <- c("cdcstatedata", class(out)) class(out) <- c("cdcstatedata", class(out))

1
R/mortalty.r

@ -76,3 +76,4 @@ get_mortality_surveillance_data <- function() {
) )
} }

2
man/get_state_data.Rd

@ -9,7 +9,7 @@ get_state_data(years = as.numeric(format(Sys.Date(), "\%Y")))
\arguments{ \arguments{
\item{years}{a vector of years to retrieve data for (i.e. \code{2014} for CDC \item{years}{a vector of years to retrieve data for (i.e. \code{2014} for CDC
flu season 2014-2015). Default value is the current year and all flu season 2014-2015). Default value is the current year and all
\code{years} values should be > \code{1997}} \code{years} values should be >= \code{2008}}
} }
\value{ \value{
A \code{data.frame} of state-level data for the specified seasons A \code{data.frame} of state-level data for the specified seasons

4
tests/testthat/test-cdcfluview.R

@ -1,6 +1,8 @@
context("basic functionality") context("basic functionality")
test_that("we can do something", { test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame")) expect_that(dim(get_flu_data("hhs", years=2015)), equals(c(520L, 15L)))
expect_that(dim(get_state_data(2008)), equals(c(2494L, 8L)))
}) })

Loading…
Cancel
Save