Browse Source

ilinet years parameter added

tags/v0.7.0
boB Rudis 3 years ago
parent
commit
6155472855
No known key found for this signature in database GPG Key ID: 2A514A4997464560
5 changed files with 85 additions and 5 deletions
  1. +1
    -0
      .Rbuildignore
  2. +44
    -0
      Makefile
  3. +30
    -3
      R/ilinet.r
  4. +8
    -1
      man/ilinet.Rd
  5. +2
    -1
      man/who_nrevss.Rd

+ 1
- 0
.Rbuildignore View File

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


+ 44
- 0
Makefile View File

@@ -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

+ 30
- 3
R/ilinet.r View File

@@ -10,6 +10,12 @@
#'
#' @md
#' @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
#' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html)
#' - [ILINet Portal](https://wwwn.cdc.gov/ilinet/) (Login required)
@@ -26,10 +32,12 @@
#' c("national", "hhs", "census", "state"),
#' ~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"))

meta <- jsonlite::fromJSON("https://gis.cdc.gov/grasp/flu2/GetPhase02InitApp?appVersion=Public")

list(
AppVersion = "Public",
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))) }
)

seasons <- 37:((unclass(as.POSIXlt(Sys.time()))[["year"]] + 1900) - 1960)
params$SeasonsDT <- lapply(seasons, function(i) list(ID=i, Name=as.character(i)))
available_seasons <- sort(meta$seasons$seasonid)

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")
td <- tempdir()


+ 8
- 1
man/ilinet.Rd View File

@@ -4,10 +4,17 @@
\alias{ilinet}
\title{Retrieve ILINet Surveillance Data}
\usage{
ilinet(region = c("national", "hhs", "census", "state"))
ilinet(region = c("national", "hhs", "census", "state"), years = NULL)
}
\arguments{
\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{
The CDC FluView Portal provides in-season and past seasons' national, regional,


+ 2
- 1
man/who_nrevss.Rd View File

@@ -32,7 +32,8 @@ HHS, Census and State data retrieval is not as "instantaneous" as their ILINet
counterparts.\cr\cr
Also, beginning for the 2015-16 season, reports from public health and clinical
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{
\dontrun{


Loading…
Cancel
Save