Browse Source

updated examples and travis config

pull/20/head
boB Rudis 5 years ago
parent
commit
86a027629f
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 84
      .travis.yml
  2. 2
      R/agd-ipt.r
  3. 4
      R/geographic-spread.R
  4. 3
      R/get-flu-data.r
  5. 2
      R/get-hosp-data.r
  6. 9
      R/get-state-data.r
  7. 6
      R/get-weekly-flu-report.r
  8. 9
      R/hospital.r
  9. 4
      R/ili-weekly-state.r
  10. 7
      R/ilinet.r
  11. 6
      R/mmwr-map.r
  12. 4
      R/pi-mortality.r
  13. 4
      R/zzz.r
  14. 2
      man/age_group_distribution.Rd
  15. 2
      man/geographic_spread.Rd
  16. 5
      man/get_flu_data.Rd
  17. 2
      man/get_hosp_data.Rd
  18. 7
      man/get_state_data.Rd
  19. 2
      man/get_weekly_flu_report.Rd
  20. 2
      man/ili_weekly_activity_indicators.Rd
  21. 7
      man/ilinet.Rd
  22. 2
      man/mmwr_week.Rd
  23. 2
      man/mmwr_week_to_date.Rd
  24. 2
      man/mmwr_weekday.Rd
  25. 2
      man/state_data_providers.Rd
  26. 2
      man/surveillance_areas.Rd

84
.travis.yml

@ -1,30 +1,54 @@
language: r language: r
r:
- release
- devel
sudo: required sudo: required
dist: trusty
cache: packages cache:
- packages
- ccache
dist: trusty latex: false
r_github_packages:
- r-dbi/DBI
- r-dbi/RPostgres
- r-lib/covr
- r-spatial/lwgeom
- r-spatial/stars
addons:
postgresql: "9.6"
apt:
sources:
- sourceline: 'ppa:opencpu/jq'
- sourceline: 'ppa:ubuntugis/ubuntugis-unstable'
- sourceline: 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main'
key_url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc'
packages:
- libprotobuf-dev
- protobuf-compiler
- libv8-3.14-dev
- libjq-dev
- libudunits2-dev
- libproj-dev
- libgeos-dev
- libspatialite-dev
- libgdal-dev
- libjson-c-dev
- libnetcdf-dev
- netcdf-bin
- postgresql-server-dev-9.6
before_install: before_install:
- sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable --yes # install postgis from source, to avoid dependency conflict with GDAL >= 2.0:
- sudo apt-get --yes --force-yes update -qq - wget http://download.osgeo.org/postgis/source/postgis-2.4.3.tar.gz
# install tmap dependencies - (mv postgis* /tmp; cd /tmp; tar xzf postgis-2.4.3.tar.gz)
- sudo apt-get install --yes libprotobuf-dev protobuf-compiler libv8-3.14-dev - (cd /tmp/postgis-2.4.3 ; ./configure; make; sudo make install)
# install tmap dependencies; for 16.04 libjq-dev this ppa is needed:
- sudo add-apt-repository -y ppa:opencpu/jq
- sudo apt-get --yes --force-yes update -qq
- sudo apt-get install libjq-dev
# units/udunits2 dependency:
- sudo apt-get install --yes libudunits2-dev
# sf dependencies:
- sudo apt-get install --yes libproj-dev libgeos-dev libgdal-dev
# postgis source compile dependencies:
- sudo apt-get --yes install libjson-c-dev postgresql-server-dev-9.6
# install postgis from source:
- wget http://download.osgeo.org/postgis/source/postgis-2.3.2.tar.gz
- (mv postgis* /tmp; cd /tmp; tar xzf postgis-2.3.2.tar.gz)
- (cd /tmp/postgis-2.3.2 ; ./configure; make; sudo make install)
# activate liblwgeom by: # activate liblwgeom by:
- sudo ldconfig - sudo ldconfig
# create postgis databases: # create postgis databases:
@ -32,21 +56,21 @@ before_install:
- createdb postgis - createdb postgis
- psql -d postgis -c "CREATE EXTENSION postgis;" - psql -d postgis -c "CREATE EXTENSION postgis;"
- psql -d postgis -c "GRANT CREATE ON DATABASE postgis TO travis" - psql -d postgis -c "GRANT CREATE ON DATABASE postgis TO travis"
- psql -d postgis -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO travis"
- createdb empty - createdb empty
- psql -d empty -c "CREATE EXTENSION postgis;" - psql -d empty -c "CREATE EXTENSION postgis;"
- R -q -e 'install.packages("remotes"); remotes::install_github("ropenscilabs/tic"); tic::prepare_all_stages()'
addons:
postgresql: "9.6"
r:
- oldrel
- release
- devel
after_success: after_success:
- dropdb postgis - dropdb postgis
- dropdb empty
- createdb postgis - createdb postgis
- psql -d postgis -c "CREATE EXTENSION postgis;" - psql -d postgis -c "CREATE EXTENSION postgis;"
- psql -d postgis -c "GRANT CREATE ON DATABASE postgis TO travis" - psql -d postgis -c "GRANT CREATE ON DATABASE postgis TO travis"
- Rscript -e 'covr::codecov()' - psql -d postgis -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO travis"
- createdb empty
- psql -d empty -c "CREATE EXTENSION postgis;"
- R -q -e 'covr::codecov(quiet = FALSE)'
install: R -q -e 'tic::install()'
script: R -q -e 'tic::script()'

2
R/agd-ipt.r

@ -16,7 +16,7 @@
#' to a year. #' to a year.
#' @export #' @export
#' @examples #' @examples
#' age_group_distribution(years=2015) #' agd <- age_group_distribution(years=2015)
age_group_distribution <- function(years = NULL) { age_group_distribution <- function(years = NULL) {
httr::GET( httr::GET(

4
R/geographic-spread.R

@ -10,7 +10,7 @@
#' to a year. #' to a year.
#' @export #' @export
#' @examples \dontrun{ #' @examples \dontrun{
#' geographic_spread() #' gs <- geographic_spread()
#' } #' }
geographic_spread <- function(years=NULL) { geographic_spread <- function(years=NULL) {
@ -57,7 +57,7 @@ geographic_spread <- function(years=NULL) {
res <- httr::content(res, as="parsed", flatten=TRUE) res <- httr::content(res, as="parsed", flatten=TRUE)
xdf <- dplyr::bind_rows(res$datadownload) suppressMessages(suppressWarnings(xdf <- dplyr::bind_rows(res$datadownload)))
xdf$weekend <- as.Date(xdf$weekend, format="%B-%d-%Y") xdf$weekend <- as.Date(xdf$weekend, format="%B-%d-%Y")
xdf xdf

3
R/get-flu-data.r

@ -30,9 +30,6 @@
#' servers to crunch the data. Wrap the function call in \code{httr::with_verbose} #' servers to crunch the data. Wrap the function call in \code{httr::with_verbose}
#' if you would like to see what's going on. #' if you would like to see what's going on.
#' @export #' @export
#' @examples \dontrun{
#' flu <- get_flu_data("hhs", 1:10, c("who", "ilinet"), years=2000:2014)
#' }
get_flu_data <- function(region="hhs", sub_region=1:10, get_flu_data <- function(region="hhs", sub_region=1:10,
data_source="ilinet", data_source="ilinet",
years=as.numeric(format(Sys.Date(), "%Y"))) { years=as.numeric(format(Sys.Date(), "%Y"))) {

2
R/get-hosp-data.r

@ -22,7 +22,7 @@
#' @export #' @export
#' @examples \dontrun{ #' @examples \dontrun{
#' # All of FluSurv-NET, 50-64 years old, 2010/11-2014/15 flu seasons #' # All of FluSurv-NET, 50-64 years old, 2010/11-2014/15 flu seasons
#' flu <- get_hosp_data("flusurvnet", "50-64y", years=2010:2014) #' hosp <- get_hosp_data("flusurvnet", "50-64y", years=2010:2014)
#' } #' }
get_hosp_data <- function(area="flusurvnet", age_group="overall", get_hosp_data <- function(area="flusurvnet", age_group="overall",
years=as.numeric(format(Sys.Date(), "%Y")) - 1) { years=as.numeric(format(Sys.Date(), "%Y")) - 1) {

9
R/get-state-data.r

@ -18,12 +18,11 @@
#' is not due to a large download size, but the time it takes for their #' is not due to a large download size, but the time it takes for their
#' servers to crunch the data. Wrap the function call in \code{httr::with_verbose} #' servers to crunch the data. Wrap the function call in \code{httr::with_verbose}
#' if you would like to see what's going on. #' if you would like to see what's going on.
#' @examples #' @examples
#' get_state_data(2014) #' state_data <- get_state_data(2014)
#' \dontrun{ #' \dontrun{
#' get_state_data(c(2013, 2014)) #' gsd <- get_state_data(c(2013, 2014))
#' get_state_data(2010:2014) #' gsd <- get_state_data(2010:2014)
#' httr::with_verbose(get_state_data(2009:2015))
#' } #' }
get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) { get_state_data <- function(years=as.numeric(format(Sys.Date(), "%Y"))) {

6
R/get-weekly-flu-report.r

@ -15,7 +15,7 @@
#' \code{label}, \code{subtitle} #' \code{label}, \code{subtitle}
#' @export #' @export
#' @examples \dontrun{ #' @examples \dontrun{
#' get_weekly_flu_report() #' wfr <- get_weekly_flu_report()
#' } #' }
get_weekly_flu_report <- function() { get_weekly_flu_report <- function() {
@ -28,6 +28,8 @@ get_weekly_flu_report <- function() {
# for each period extract the state information and # for each period extract the state information and
# shove it all into a data frame # shove it all into a data frame
pb <- dplyr::progress_estimated(length(periods)) pb <- dplyr::progress_estimated(length(periods))
suppressWarnings(suppressMessages(
purrr::map_df(periods, function(period) { purrr::map_df(periods, function(period) {
pb$tick()$print() pb$tick()$print()
@ -51,7 +53,7 @@ get_weekly_flu_report <- function() {
subtitle = period["subtitle"] subtitle = period["subtitle"]
) )
}) -> out }) -> out))
class(out) <- c("cdcweeklyreport", class(out)) class(out) <- c("cdcweeklyreport", class(out))

9
R/hospital.r

@ -16,7 +16,7 @@
#' @references #' @references
#' - [Hospital Portal](https://gis.cdc.gov/GRASP/Fluview/FluHospRates.html) #' - [Hospital Portal](https://gis.cdc.gov/GRASP/Fluview/FluHospRates.html)
#' @export #' @export
#' @examples #' @examples
#' hosp_fs <- hospitalizations("flusurv", years=2015) #' hosp_fs <- hospitalizations("flusurv", years=2015)
#' \dontrun{ #' \dontrun{
#' hosp_eip <- hospitalizations("eip") #' hosp_eip <- hospitalizations("eip")
@ -76,16 +76,17 @@ hospitalizations <- function(surveillance_area=c("flusurv", "eip", "ihsp"),
ser_names <- unlist(hosp$res$busdata$datafields, use.names = FALSE) ser_names <- unlist(hosp$res$busdata$datafields, use.names = FALSE)
mmwr_df <- bind_rows(hosp$res$mmwr) suppressWarnings(suppressMessages(mmwr_df <- dplyr::bind_rows(hosp$res$mmwr)))
mmwr_df <- mmwr_df[,c("mmwrid", "weekend", "weeknumber", "weekstart", "year", mmwr_df <- mmwr_df[,c("mmwrid", "weekend", "weeknumber", "weekstart", "year",
"yearweek", "seasonid", "weekendlabel", "weekendlabel2")] "yearweek", "seasonid", "weekendlabel", "weekendlabel2")]
suppressMessages(suppressWarnings(
dplyr::bind_rows(lapply(hosp$res$busdata$dataseries, function(.x) { dplyr::bind_rows(lapply(hosp$res$busdata$dataseries, function(.x) {
tdf <- dplyr::bind_rows(lapply(.x$data, function(.x) setNames(.x, ser_names))) tdf <- dplyr::bind_rows(lapply(.x$data, function(.x) setNames(.x, ser_names)))
tdf$age <- .x$age tdf$age <- .x$age
tdf$season <- .x$season tdf$season <- .x$season
tdf tdf
})) -> xdf })) -> xdf))
dplyr::left_join(xdf, mmwr_df, c("mmwrid", "weeknumber")) %>% dplyr::left_join(xdf, mmwr_df, c("mmwrid", "weeknumber")) %>%
dplyr::left_join(age_df, "age") %>% dplyr::left_join(age_df, "age") %>%
@ -137,7 +138,7 @@ hospitalizations <- function(surveillance_area=c("flusurv", "eip", "ihsp"),
#' @md #' @md
#' @export #' @export
#' @examples #' @examples
#' surveillance_areas() #' sa <- surveillance_areas()
surveillance_areas <- function() { surveillance_areas <- function() {
meta <- jsonlite::fromJSON("https://gis.cdc.gov/GRASP/Flu3/GetPhase03InitApp?appVersion=Public") meta <- jsonlite::fromJSON("https://gis.cdc.gov/GRASP/Flu3/GetPhase03InitApp?appVersion=Public")
xdf <- setNames(meta$catchments[,c("name", "area")], c("surveillance_area", "region")) xdf <- setNames(meta$catchments[,c("name", "area")], c("surveillance_area", "region"))

4
R/ili-weekly-state.r

@ -25,7 +25,7 @@
#' with data presented by the state likely being the more complete. #' with data presented by the state likely being the more complete.
#' @export #' @export
#' @examples \dontrun{ #' @examples \dontrun{
#' ili_weekly_activity_indicators(2016) #' iwai <- ili_weekly_activity_indicators(2016)
#' } #' }
ili_weekly_activity_indicators <- function(years=NULL) { ili_weekly_activity_indicators <- function(years=NULL) {
@ -78,7 +78,7 @@ ili_weekly_activity_indicators <- function(years=NULL) {
#' @md #' @md
#' @export #' @export
#' @examples #' @examples
#' state_data_providers() #' sdp <- state_data_providers()
state_data_providers <- function() { state_data_providers <- function() {
jsonlite::fromJSON("https://gis.cdc.gov/grasp/fluView1/Phase1IniP") %>% jsonlite::fromJSON("https://gis.cdc.gov/grasp/fluView1/Phase1IniP") %>%

7
R/ilinet.r

@ -28,11 +28,8 @@
#' census_ili <- ilinet("census") #' census_ili <- ilinet("census")
#' state_ili <- ilinet("state") #' state_ili <- ilinet("state")
#' #'
#' library(purrr) #' all_ili <- suppressWarnings(
#' map_df( #' suppressMessages(purrr::map_df(c("national", "hhs", "census", "state"), ilinet)))
#' c("national", "hhs", "census", "state"),
#' ~ ilinet(.x)
#' )
#' } #' }
ilinet <- function(region = c("national", "hhs", "census", "state"), years = NULL) { ilinet <- function(region = c("national", "hhs", "census", "state"), years = NULL) {

6
R/mmwr-map.r

@ -53,7 +53,7 @@ NULL
#' @return data frame (tibble) #' @return data frame (tibble)
#' @export #' @export
#' @examples #' @examples
#' mmwr_week(Sys.Date()) #' mwk <- mmwr_week(Sys.Date())
mmwr_week <- function(x) { mmwr_week <- function(x) {
x <- as.Date(x) x <- as.Date(x)
x <- setNames(MMWRweek::MMWRweek(x), c("mmwr_year", "mmwr_week", "mmwr_day")) x <- setNames(MMWRweek::MMWRweek(x), c("mmwr_year", "mmwr_week", "mmwr_day"))
@ -76,7 +76,7 @@ mmwr_week <- function(x) {
#' @return ordered factor #' @return ordered factor
#' @export #' @export
#' @examples #' @examples
#' mmwr_weekday(Sys.Date()) #' mwday <- mmwr_weekday(Sys.Date())
mmwr_weekday <- function(x, abbr = FALSE) { mmwr_weekday <- function(x, abbr = FALSE) {
x <- as.Date(x) x <- as.Date(x)
x <- MMWRweek::MMWRweekday(x) x <- MMWRweek::MMWRweekday(x)
@ -103,7 +103,7 @@ mmwr_weekday <- function(x, abbr = FALSE) {
#' @return vector of `Date` objects #' @return vector of `Date` objects
#' @export #' @export
#' @examples #' @examples
#' mmwr_week_to_date(2016,10,3) #' mwd <- mmwr_week_to_date(2016,10,3)
mmwr_week_to_date <- function(year, week, day=NULL) { mmwr_week_to_date <- function(year, week, day=NULL) {
year <- as.numeric(year) year <- as.numeric(year)

4
R/pi-mortality.r

@ -114,11 +114,11 @@ pi_mortality <- function(coverage_area=c("national", "state", "region"), years=N
res <- httr::content(res, as="parsed", flatten=TRUE) res <- httr::content(res, as="parsed", flatten=TRUE)
dplyr::bind_rows(res$seasons) %>% suppressWarnings(suppressMessages(dplyr::bind_rows(res$seasons) %>%
dplyr::left_join(mapcode_df, "map_code") %>% dplyr::left_join(mapcode_df, "map_code") %>%
dplyr::left_join(geo_df, "geoid") %>% dplyr::left_join(geo_df, "geoid") %>%
dplyr::left_join(age_df, "ageid") %>% dplyr::left_join(age_df, "ageid") %>%
dplyr::left_join(dplyr::mutate(mmwrid_map, mmwrid=as.character(mmwrid)), "mmwrid") -> xdf dplyr::left_join(dplyr::mutate(mmwrid_map, mmwrid=as.character(mmwrid)), "mmwrid") -> xdf))
xdf <- dplyr::mutate(xdf, coverage_area = coverage_area) xdf <- dplyr::mutate(xdf, coverage_area = coverage_area)

4
R/zzz.r

@ -7,8 +7,4 @@
"See https://github.com/hrbrmstr/cdcfluview for info/news.")) "See https://github.com/hrbrmstr/cdcfluview for info/news."))
} }
# packageStartupMessage(paste0("cdcfluview is under *active* development. ",
# "There are numerous changes & dprecations.\n",
# "See https://github.com/hrbrmstr/cdcfluview for info/news."))
} # nocov end } # nocov end

2
man/age_group_distribution.Rd

@ -20,7 +20,7 @@ public health laboratories by influenza virus type and subtype/lineage. Laborato
from multiple seasons and different age groups is provided. from multiple seasons and different age groups is provided.
} }
\examples{ \examples{
age_group_distribution(years=2015) agd <- age_group_distribution(years=2015)
} }
\references{ \references{
\itemize{ \itemize{

2
man/geographic_spread.Rd

@ -20,6 +20,6 @@ State and Territorial Epidemiologists Reports of Geographic Spread of Influenza
} }
\examples{ \examples{
\dontrun{ \dontrun{
geographic_spread() gs <- geographic_spread()
} }
} }

5
man/get_flu_data.Rd

@ -48,8 +48,3 @@ There is often a noticeable delay when making the API request to the CDC.
servers to crunch the data. Wrap the function call in \code{httr::with_verbose} servers to crunch the data. Wrap the function call in \code{httr::with_verbose}
if you would like to see what's going on. if you would like to see what's going on.
} }
\examples{
\dontrun{
flu <- get_flu_data("hhs", 1:10, c("who", "ilinet"), years=2000:2014)
}
}

2
man/get_hosp_data.Rd

@ -38,6 +38,6 @@ There is often a noticeable delay when making the API request to the CDC.
\examples{ \examples{
\dontrun{ \dontrun{
# All of FluSurv-NET, 50-64 years old, 2010/11-2014/15 flu seasons # All of FluSurv-NET, 50-64 years old, 2010/11-2014/15 flu seasons
flu <- get_hosp_data("flusurvnet", "50-64y", years=2010:2014) hosp <- get_hosp_data("flusurvnet", "50-64y", years=2010:2014)
} }
} }

7
man/get_state_data.Rd

@ -31,10 +31,9 @@ There is often a noticeable delay when making the API request to the CDC. This
if you would like to see what's going on. if you would like to see what's going on.
} }
\examples{ \examples{
get_state_data(2014) state_data <- get_state_data(2014)
\dontrun{ \dontrun{
get_state_data(c(2013, 2014)) gsd <- get_state_data(c(2013, 2014))
get_state_data(2010:2014) gsd <- get_state_data(2010:2014)
httr::with_verbose(get_state_data(2009:2015))
} }
} }

2
man/get_weekly_flu_report.Rd

@ -23,7 +23,7 @@ the reporting source metadata and a limit on the historical flu information.
} }
\examples{ \examples{
\dontrun{ \dontrun{
get_weekly_flu_report() wfr <- get_weekly_flu_report()
} }
} }
\references{ \references{

2
man/ili_weekly_activity_indicators.Rd

@ -35,7 +35,7 @@ with data presented by the state likely being the more complete.
} }
\examples{ \examples{
\dontrun{ \dontrun{
ili_weekly_activity_indicators(2016) iwai <- ili_weekly_activity_indicators(2016)
} }
} }
\references{ \references{

7
man/ilinet.Rd

@ -33,11 +33,8 @@ hhs_ili <- ilinet("hhs")
census_ili <- ilinet("census") census_ili <- ilinet("census")
state_ili <- ilinet("state") state_ili <- ilinet("state")
library(purrr) all_ili <- suppressWarnings(
map_df( suppressMessages(purrr::map_df(c("national", "hhs", "census", "state"), ilinet)))
c("national", "hhs", "census", "state"),
~ ilinet(.x)
)
} }
} }
\references{ \references{

2
man/mmwr_week.Rd

@ -17,5 +17,5 @@ This is a reformat and re-export of a function in the \code{MMWRweek} package.
It provides a snake case version of its counterpart, produces a \code{tibble} It provides a snake case version of its counterpart, produces a \code{tibble}
} }
\examples{ \examples{
mmwr_week(Sys.Date()) mwk <- mmwr_week(Sys.Date())
} }

2
man/mmwr_week_to_date.Rd

@ -20,5 +20,5 @@ of \code{Date} objects that corresponds to the input MMWR year+week or year+week
vectors. This also adds some parameter checking and cleanup to avoid exceptions. vectors. This also adds some parameter checking and cleanup to avoid exceptions.
} }
\examples{ \examples{
mmwr_week_to_date(2016,10,3) mwd <- mmwr_week_to_date(2016,10,3)
} }

2
man/mmwr_weekday.Rd

@ -25,5 +25,5 @@ Weekday names are explicitly mapped to "Sunday-Saturday" or "Sun-Sat" and
do not change with your locale. do not change with your locale.
} }
\examples{ \examples{
mmwr_weekday(Sys.Date()) mwday <- mmwr_weekday(Sys.Date())
} }

2
man/state_data_providers.Rd

@ -10,5 +10,5 @@ state_data_providers()
Retrieve metadata about U.S. State CDC Provider Data Retrieve metadata about U.S. State CDC Provider Data
} }
\examples{ \examples{
state_data_providers() sdp <- state_data_providers()
} }

2
man/surveillance_areas.Rd

@ -10,5 +10,5 @@ surveillance_areas()
Retrieve a list of valid sub-regions for each surveillance area. Retrieve a list of valid sub-regions for each surveillance area.
} }
\examples{ \examples{
surveillance_areas() sa <- surveillance_areas()
} }

Loading…
Cancel
Save