From 0912f15f1c311f443fc07568c849ab226849240e Mon Sep 17 00:00:00 2001 From: Bob Rudis Date: Mon, 2 Jan 2017 14:50:07 -0500 Subject: [PATCH] get_flu_data() will choose current flu season if years parameter is set to the current year but has no return data (i.e. the "next year's" flu season hasn't started) --- DESCRIPTION | 4 ++-- NEWS.md | 8 +++++++- R/get_flu_data.r | 14 +++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 050a876..1f4dc47 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: cdcfluview Type: Package Title: Retrieve U.S. Flu Season Data from the CDC FluView Portal -Version: 0.5.1 -Date: 2016-12-06 +Version: 0.5.2 +Date: 2017-01-02 Author: Bob Rudis (bob@rud.is) Maintainer: Bob Rudis Encoding: UTF-8 diff --git a/NEWS.md b/NEWS.md index ee01fad..b542cda 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,10 @@ -# cscfluview 0.5.1 +# cdcfluview 0.5.2 + +* Modified behavior of `get_flu_data()` to actually grab current flu season year + if a single year was specified and it is the current year and the return is a 0 length + data frame #7 + +# cdcfluview 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) diff --git a/R/get_flu_data.r b/R/get_flu_data.r index 695d023..4cf964c 100644 --- a/R/get_flu_data.r +++ b/R/get_flu_data.r @@ -98,7 +98,19 @@ get_flu_data <- function(region="hhs", sub_region=1:10, names(file_list) <- substr(basename(files), 1, 3) if (length(file_list) == 1) { - return(file_list[[1]]) + + file_list <- file_list[[1]] + + if ((nrow(file_list) == 0) & + (length(years)==1) & + (years == (as.numeric(format(Sys.Date(), "%Y"))-1960))) { + + message("Adjusting [years] to get current season...") + return(get_flu_data(region=region, sub_region=sub_region, + data_source=data_source, years=years+1960-1)) + } else { + return(file_list) + } } else { return(file_list) }