diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index d8aeb54..c77bffb 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -33,9 +33,6 @@ jobs: - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index 7af0bd7..3ed99f3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidyqwi Title: A Convenient API for Accessing United States Census Bureau's Quarterly Workforce Indicator -Version: 0.1.2 +Version: 0.1.3 Authors@R: c( person(given = "Michael", family = "DeWitt", @@ -26,7 +26,7 @@ Description: The purpose of this package is to access the Quarterly Workforce Indicator is available at . Depends: - R (>= 3.2), + R (>= 3.5), future (>= 1.6.2) Imports: dplyr, @@ -44,10 +44,12 @@ License: MIT + file LICENSE BugReports: https://github.com/medewitt/tidyqwi/issues Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.3.1 Suggests: testthat, covr, knitr, - rmarkdown + rmarkdown, + spelling VignetteBuilder: knitr +Language: en-US diff --git a/NEWS.md b/NEWS.md index 9b1db23..8967050 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# tidyqwu 0.1.3 +* Adds capability for pulling workforce investment areas via @mrembart via PR #31. +* Internal changes due to changes in `tidyr` and `dplyr` +* Misc internal upkeep regarding Census API + # tidyqwi 0.1.2 * Internal changes in preparation for `dplyr` v1.0.0 diff --git a/R/check_census_api_call.R b/R/check_census_api_call.R index 38de003..a6a8a4f 100644 --- a/R/check_census_api_call.R +++ b/R/check_census_api_call.R @@ -8,31 +8,47 @@ #' @param call a returned call from the US Census API #' @import xml2 #' @import httr -#'@examples \donttest{ +#'@examples +#' +#' if(FALSE){ #'library(tidyqwi) #'library(httr) #' # A single call to the API without an API Key #'url <- "api.census.gov/data/timeseries/qwi/sa?get=Emp&for=county:198&key=NOKEY" #'single_call <- httr::GET(url) +#' stop_for_status(single_call) #' #'# Because a non valid API key was specified an message will be returned #' -#'check_census_api_call(single_call) -#' +#' check_census_api_call(single_call) #'} +#' #' @return a string vector with the message from the US Census API #' @export check_census_api_call <- function(call){ + + if(class(call) != "response"){ stop("A valid response was not returned") } + if( grepl("Invalid", call %>% + httr::content(encoding = "UTF-8") %>% + xml2::as_xml_document()%>% + xml2::xml_find_all("head") %>% + xml2::xml_text())) { + + stop("A valid key must be included with each data API request.") + } returned_call <- httr::content(call, as = "text", encoding = "UTF-8") - if( show_condition(xml2::as_xml_document(returned_call)["node"]) !="error"){ + + + + if( class(show_condition(xml2::as_xml_document(returned_call)["node"])) !="error"){ returned_call %>% xml2::as_xml_document()%>% xml2::xml_find_all("body") %>% diff --git a/R/get_qwi.R b/R/get_qwi.R index 0741b21..d6bfcf8 100644 --- a/R/get_qwi.R +++ b/R/get_qwi.R @@ -175,7 +175,7 @@ get_qwi <- function(years, if(!endpoint %in% c("sa", "se", "rh")){ - stop(sprintf("You have not specified a valid endpoint one of `sa``, `se``, or `rh`", endpoint)) + stop(sprintf("You have not specified a valid endpoint one of `sa``, `se``, or `rh`")) } endpoint_to_retrieve <- switch( endpoint, @@ -263,11 +263,11 @@ get_qwi <- function(years, call <- httr::GET(urls$url[[1]]) - if(!substr(call$status_code,1,1) == "2"| - show_condition(check_census_api_call(call))!="error"){ + if(!substr(call$status_code, 1, 1) == "2" || + class(show_condition(check_census_api_call(call)))!="error") { # IF 200 was not returned then there was an error. - if(grepl(pattern = "valid key must", check_census_api_call(call))){ + if(grepl(pattern = "valid key must", check_census_api_call(call))) { stop(check_census_api_call(call)) } } @@ -276,7 +276,7 @@ get_qwi <- function(years, #results <- purrr::map(urls$url, httr::GET) results <- vector("list", length = nrow(urls)) - for(i in 1:nrow(urls)){ + for(i in 1:nrow(urls)) { results[[i]] <- httr::GET(urls$url[[i]]) #print(paste0(i, "out of", nrow(urls))) } @@ -292,7 +292,7 @@ get_qwi <- function(years, a<- purrr::transpose(output)[["result"]] - non_error_returns <- tidyr::spread_( + non_error_returns <- tidyr::spread( dplyr::bind_rows( purrr::compact(a)), "parameter", "value", fill = NA) diff --git a/R/parse_qwi_message.R b/R/parse_qwi_message.R index cdc35d4..be85f55 100644 --- a/R/parse_qwi_message.R +++ b/R/parse_qwi_message.R @@ -7,7 +7,7 @@ parse_qwi_message <- function(x) { if (class(x) != "response") { stop("You have not passed a valid response") } - y <- dplyr::as_data_frame( + y <- dplyr::as_tibble( jsonlite::fromJSON( httr::content(x, as = "text", encoding = "UTF-8") ) diff --git a/R/utils.R b/R/utils.R index 742c43d..643522a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,6 +5,7 @@ utils::data("owner_codes", package=pkgname, envir=parent.env(environment())) utils::data("qwi_var_names", package=pkgname, envir=parent.env(environment())) utils::data("state_info", package=pkgname, envir=parent.env(environment())) + utils::data("geo_codes", package=pkgname, envir=parent.env(environment())) } # Helper for trycatching in the code @@ -21,3 +22,6 @@ show_condition <- function(code) { +globalVariables({ + c("geo_codes", "geo_level", "state_fips") +}) \ No newline at end of file diff --git a/cran-comments.md b/cran-comments.md index 1eb69b8..1463f6e 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,15 +1,16 @@ ## Release Summary -This is a minor release. (v0.1.1 to v0.1.2) +This is a minor release. (v0.1.2 to v0.1.3) -* Fixes in preparation for dplyr 1.0.0 -* Added to documentation to specify returned objects per guidelines +* Fixes graceful failure to a web API +* Internal updates ## Test environments -* local OS X install, R 4.0 -* ubuntu 14.04 (on travis-ci), R 4.0 (devel + release) -* local win-builder (release) R 4.0 +* local OS X install, R 4.3 +* GitHub Actions + * Windows (release, 3.6) + * MacOS (release) + * Ubuntu (release, devel) ## R CMD check results 0 errors | 0 warnings | 0 notes - diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 0000000..495b550 --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,25 @@ +AppVeyor +DOI +FIP +FIPs +Indcator +MSA +Orcid +QWI +Quaterly +cbsa +fips +geolevel +granuality +lifecycle +ownercode +qwi +retrive +rh +sa +se +sucessful +tibble +tidyqwi’ +tidyqwu +troublshooting diff --git a/man/check_census_api_call.Rd b/man/check_census_api_call.Rd index 6bf668d..b729225 100644 --- a/man/check_census_api_call.Rd +++ b/man/check_census_api_call.Rd @@ -18,16 +18,18 @@ If the call was not sucessful, this function passes the message received from the US Census API for further troublshooting, } \examples{ -\donttest{ + +if(FALSE){ library(tidyqwi) library(httr) # A single call to the API without an API Key url <- "api.census.gov/data/timeseries/qwi/sa?get=Emp&for=county:198&key=NOKEY" single_call <- httr::GET(url) +stop_for_status(single_call) # Because a non valid API key was specified an message will be returned check_census_api_call(single_call) - } + } diff --git a/man/geo_codes.Rd b/man/geo_codes.Rd new file mode 100644 index 0000000..6eff81e --- /dev/null +++ b/man/geo_codes.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/geo_codes.R +\docType{data} +\name{geo_codes} +\alias{geo_codes} +\title{Geographic Codes} +\format{ +a dataframe with 5423 rows and 3 columns: +\describe{ + \item{geography}{geography} + \item{label}{label} + \item{geolevel}{geolevel} + ... +} +} +\source{ +\url{https://lehd.ces.census.gov/data/schema/latest/label_geography.csv} +} +\usage{ +geo_codes +} +\description{ +Geographic Codes +} +\keyword{datasets} diff --git a/tests/spelling.R b/tests/spelling.R new file mode 100644 index 0000000..6713838 --- /dev/null +++ b/tests/spelling.R @@ -0,0 +1,3 @@ +if(requireNamespace('spelling', quietly = TRUE)) + spelling::spell_check_test(vignettes = TRUE, error = FALSE, + skip_on_cran = TRUE) diff --git a/tests/testthat/test.R b/tests/testthat/test.R index 315edbb..2bb4417 100644 --- a/tests/testthat/test.R +++ b/tests/testthat/test.R @@ -26,7 +26,7 @@ test_that("Catch for correct variables", { }) test_that("Catch for endpoint checking", { - expect_error(get_qwi(years = c(2011), states = c("01"), apikey = "MYKEY", endpoint = "RR"), + expect_error(get_qwi(years = c(2011), states = c("01"), apikey = "MYKEY", endpoint = "RR", variables = "EarnBeg"), "You have not specified a valid endpoint one of `sa``, `se``, or `rh`") }) @@ -44,7 +44,7 @@ test_that("Catch for seasonal adjustment", { test_that("Valid API Key", { skip_on_cran() expect_error(get_qwi(years = c(2011), states = c("01"), apikey = "A"), - "A valid key must be included with each data API request. You included a key with this request, however, it is not valid. Please check your key and try again.If you do not have a key you my sign up for one here. ") + "A valid key must be included with each data API request.") }) # check that labels fails