Browse Source

fixed state data d/l & added tests+travis

tags/v0.5.2
boB Rudis 4 years ago
parent
commit
0df2fdf1e0
11 changed files with 28 additions and 49 deletions
  1. +1
    -1
      .Rbuildignore
  2. +4
    -22
      .travis.yml
  3. +3
    -1
      DESCRIPTION
  4. +1
    -0
      NAMESPACE
  5. +1
    -0
      NEWS.md
  6. +1
    -0
      R/aaa.r
  7. +1
    -0
      R/cdcfluview-package.R
  8. +11
    -23
      R/get_state_data.r
  9. +1
    -0
      R/mortalty.r
  10. +1
    -1
      man/get_state_data.Rd
  11. +3
    -1
      tests/testthat/test-cdcfluview.R

+ 1
- 1
.Rbuildignore View File

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

+ 4
- 22
.travis.yml View File

@ -1,23 +1,5 @@
language: c
# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
before_install:
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
- chmod 755 ./travis-tool.sh
- ./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
language: R
sudo: false
cache: packages

+ 3
- 1
DESCRIPTION View File

@ -5,6 +5,7 @@ Version: 0.5.1
Date: 2016-12-05
Author: 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
<http://gis.cdc.gov/grasp/fluview/fluportaldashboard.html> for
accessing state, regional and national influenza statistics as well as
@ -23,7 +24,8 @@ Imports:
dplyr,
utils,
purrr,
readr
readr,
V8
Depends:
R (>= 3.2.0)
RoxygenNote: 5.0.1

+ 1
- 0
NAMESPACE View File

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


+ 1
- 0
NEWS.md View File

@ -1,6 +1,7 @@
# cscfluview 0.5.1
* 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


+ 1
- 0
R/aaa.r View File

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

+ 1
- 0
R/cdcfluview-package.R View File

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

+ 11
- 23
R/get_state_data.r View File

@ -10,7 +10,7 @@
#'
#' @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
#' \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
#' (also classed as \code{cdcstatedata})
#' @export
@ -26,34 +26,22 @@
#' }
get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) {
if (any(years < 1997))
stop("Error: years should be > 1997")
if (any(years < 2008))
stop("Error: years should be >= 2008")
years <- years - 1960
years <- c((years - 1960), 1)
years <- paste0(years, collapse=",")
out_file <- tempfile(fileext=".zip")
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))
tmp <- httr::GET(sprintf("https://gis.cdc.gov/grasp/fluView1/Phase1DownloadDataP/%s", years))
stop_for_status(tmp)
if (!(file.exists(out_file)))
stop("Error: cannot process downloaded data")
out_dir <- tempdir()
files <- unzip(out_file, exdir=out_dir, overwrite=TRUE)
res <- httr::content(tmp, as="parsed")
out <- read.csv(files, header=TRUE, stringsAsFactors=FALSE)
# out <- readr::read_csv(files, col_types="cccccic")
ctx <- v8()
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))


+ 1
- 0
R/mortalty.r View File

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

+ 1
- 1
man/get_state_data.Rd View File

@ -9,7 +9,7 @@ get_state_data(years = as.numeric(format(Sys.Date(), "\%Y")))
\arguments{
\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
\code{years} values should be > \code{1997}}
\code{years} values should be >= \code{2008}}
}
\value{
A \code{data.frame} of state-level data for the specified seasons


+ 3
- 1
tests/testthat/test-cdcfluview.R View File

@ -1,6 +1,8 @@
context("basic functionality")
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