Browse Source

ilinet years parameter added

tags/v0.7.0
boB Rudis 7 years ago
parent
commit
6155472855
No known key found for this signature in database GPG Key ID: 2A514A4997464560
  1. 1
      .Rbuildignore
  2. 44
      Makefile
  3. 33
      R/ilinet.r
  4. 9
      man/ilinet.Rd
  5. 3
      man/who_nrevss.Rd

1
.Rbuildignore

@ -14,6 +14,7 @@
^\.Rproj\.user$ ^\.Rproj\.user$
^\.travis\.yml$ ^\.travis\.yml$
^.*md$ ^.*md$
^crunch
^crunch/ ^crunch/
^crunch/.* ^crunch/.*
^README_files/ ^README_files/

44
Makefile

@ -0,0 +1,44 @@
PACKAGE := $(shell grep '^Package:' DESCRIPTION | sed -E 's/^Package:[[:space:]]+//')
RSCRIPT = Rscript --no-init-file
all: install
test:
${RSCRIPT} -e 'library(methods); devtools::test()'
roxygen:
@mkdir -p man
${RSCRIPT} -e "library(methods); devtools::document()"
install:
R CMD INSTALL .
build:
R CMD build .
check:
_R_CHECK_CRAN_INCOMING_=FALSE make check_all
check_all:
${RSCRIPT} -e "rcmdcheck::rcmdcheck(args = c('--as-cran', '--no-manual'))"
staticdocs:
@mkdir -p inst/staticdocs
${RSCRIPT} -e "library(methods); staticdocs::build_site()"
rm -f vignettes/*.html
@rmdir inst/staticdocs
website: staticdocs
./update_web.sh
README.md: README.Rmd
Rscript -e 'library(methods); devtools::load_all(); knitr::knit("README.Rmd")'
sed -i.bak 's/[[:space:]]*$$//' $@
rm -f $@.bak
vignettes/%.Rmd: vignettes/src/%.R
${RSCRIPT} -e 'library(sowsear); sowsear("$<", output="$@")'
vignettes: vignettes/cyphr.Rmd vignettes/data.Rmd
${RSCRIPT} -e 'library(methods); devtools::build_vignettes()'
# No real targets!
.PHONY: all test document install vignettes

33
R/ilinet.r

@ -10,6 +10,12 @@
#' #'
#' @md #' @md
#' @param region one of "`national`", "`hhs`", "`census`", or "`state`" #' @param region one of "`national`", "`hhs`", "`census`", or "`state`"
#' @param years a vector of years to retrieve data for (i.e. `2014` for CDC
#' flu season 2014-2015). CDC has data for this API going back to 1997.
#' Default value (`NULL`) means retrieve **all** years. NOTE: if you
#' happen to specify a 2-digit season value (i.e. `57` == 2017-2018)
#' the function is smart enough to retrieve by season ID vs convert that
#' to a year.
#' @references #' @references
#' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html) #' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html)
#' - [ILINet Portal](https://wwwn.cdc.gov/ilinet/) (Login required) #' - [ILINet Portal](https://wwwn.cdc.gov/ilinet/) (Login required)
@ -26,10 +32,12 @@
#' c("national", "hhs", "census", "state"), #' c("national", "hhs", "census", "state"),
#' ~ilinet(.x) %>% readr::type_convert()) #' ~ilinet(.x) %>% readr::type_convert())
#' } #' }
ilinet <- function(region=c("national", "hhs", "census", "state")) { ilinet <- function(region=c("national", "hhs", "census", "state"), years=NULL) {
region <- match.arg(tolower(region), c("national", "hhs", "census", "state")) region <- match.arg(tolower(region), c("national", "hhs", "census", "state"))
meta <- jsonlite::fromJSON("https://gis.cdc.gov/grasp/flu2/GetPhase02InitApp?appVersion=Public")
list( list(
AppVersion = "Public", AppVersion = "Public",
DatasourceDT = list(list(ID = 1, Name = "ILINet")), DatasourceDT = list(list(ID = 1, Name = "ILINet")),
@ -43,8 +51,27 @@ ilinet <- function(region=c("national", "hhs", "census", "state")) {
state = { lapply(1:59, function(i) list(ID=i, Name=as.character(i))) } state = { lapply(1:59, function(i) list(ID=i, Name=as.character(i))) }
) )
seasons <- 37:((unclass(as.POSIXlt(Sys.time()))[["year"]] + 1900) - 1960) available_seasons <- sort(meta$seasons$seasonid)
params$SeasonsDT <- lapply(seasons, function(i) list(ID=i, Name=as.character(i)))
if (is.null(years)) { # ALL YEARS
years <- available_seasons
} else { # specified years or seasons or a mix
years <- as.numeric(years)
years <- ifelse(years > 1996, years - 1960, years)
years <- sort(unique(years))
years <- years[years %in% available_seasons]
if (length(years) == 0) {
years <- rev(sort(meta$seasons$seasonid))[1]
curr_season_descr <- meta$seasons[meta$seasons$seasonid == years, "description"]
message(sprintf("No valid years specified, defaulting to this flu season => ID: %s [%s]",
years, curr_season_descr))
}
}
params$SeasonsDT <- lapply(years, function(i) list(ID=i, Name=as.character(i)))
tf <- tempfile(fileext = ".zip") tf <- tempfile(fileext = ".zip")
td <- tempdir() td <- tempdir()

9
man/ilinet.Rd

@ -4,10 +4,17 @@
\alias{ilinet} \alias{ilinet}
\title{Retrieve ILINet Surveillance Data} \title{Retrieve ILINet Surveillance Data}
\usage{ \usage{
ilinet(region = c("national", "hhs", "census", "state")) ilinet(region = c("national", "hhs", "census", "state"), years = NULL)
} }
\arguments{ \arguments{
\item{region}{one of "\code{national}", "\code{hhs}", "\code{census}", or "\code{state}"} \item{region}{one of "\code{national}", "\code{hhs}", "\code{census}", or "\code{state}"}
\item{years}{a vector of years to retrieve data for (i.e. \code{2014} for CDC
flu season 2014-2015). CDC has data for this API going back to 1997.
Default value (\code{NULL}) means retrieve \strong{all} years. NOTE: if you
happen to specify a 2-digit season value (i.e. \code{57} == 2017-2018)
the function is smart enough to retrieve by season ID vs convert that
to a year.}
} }
\description{ \description{
The CDC FluView Portal provides in-season and past seasons' national, regional, The CDC FluView Portal provides in-season and past seasons' national, regional,

3
man/who_nrevss.Rd

@ -32,7 +32,8 @@ HHS, Census and State data retrieval is not as "instantaneous" as their ILINet
counterparts.\cr\cr counterparts.\cr\cr
Also, beginning for the 2015-16 season, reports from public health and clinical Also, beginning for the 2015-16 season, reports from public health and clinical
laboratories are presented separately in the weekly influenza update. This is laboratories are presented separately in the weekly influenza update. This is
the reason why a list of data frames is returned. the reason why a list of data frames is returned.\cr\cr
\strong{ALSO} The new CDC API seems to be missing some public health lab data fields.
} }
\examples{ \examples{
\dontrun{ \dontrun{

Loading…
Cancel
Save