Browse Source

added years parameter to agdipt

tags/v0.7.0
boB Rudis 6 years ago
parent
commit
3922f6bd85
No known key found for this signature in database GPG Key ID: 2A514A4997464560
  1. 28
      R/agd-ipt.r
  2. 10
      man/age_group_distribution.Rd

28
R/agd-ipt.r

@ -7,11 +7,17 @@
#' @references #' @references
#' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html) #' - [CDC FluView Portal](https://gis.cdc.gov/grasp/fluview/fluportaldashboard.html)
#' - [AGD IPT Portal](https://gis.cdc.gov/grasp/fluview/flu_by_age_virus.html) #' - [AGD IPT Portal](https://gis.cdc.gov/grasp/fluview/flu_by_age_virus.html)
#' @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.
#' @export #' @export
#' @examples \dontrun{ #' @examples \dontrun{
#' agd_ipt() #' agd_ipt()
#' } #' }
age_group_distribution <- function() { age_group_distribution <- function(years = NULL) {
httr::GET( httr::GET(
url = "https://gis.cdc.gov/grasp/fluView6/GetFlu6AllDataP", url = "https://gis.cdc.gov/grasp/fluView6/GetFlu6AllDataP",
@ -58,6 +64,26 @@ age_group_distribution <- function() {
vir_df <- dplyr::left_join(vir_df, mmwrid_map, "mmwrid") vir_df <- dplyr::left_join(vir_df, mmwrid_map, "mmwrid")
available_seasons <- sort(unique(vir_df$seasonid))
if (!is.null(years)) { # 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(available_seasons)[1]
curr_season_descr <- vir_df[vir_df$seasonid == years,]$sea_description[1]
message(sprintf("No valid years specified, defaulting to this flu season => ID: %s [%s]",
years, curr_season_descr))
}
vir_df <- dplyr::filter(vir_df, seasonid %in% years)
}
vir_df vir_df
} }

10
man/age_group_distribution.Rd

@ -4,7 +4,15 @@
\alias{age_group_distribution} \alias{age_group_distribution}
\title{Age Group Distribution of Influenza Positive Tests Reported by Public Health Laboratories} \title{Age Group Distribution of Influenza Positive Tests Reported by Public Health Laboratories}
\usage{ \usage{
age_group_distribution() age_group_distribution(years = NULL)
}
\arguments{
\item{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.}
} }
\description{ \description{
Retrieves the age group distribution of influenza positive tests that are reported by Retrieves the age group distribution of influenza positive tests that are reported by

Loading…
Cancel
Save