Skip to content

Commit

Permalink
Revert "Initial commit for LODES8"
Browse files Browse the repository at this point in the history
This reverts commit fe600da.
  • Loading branch information
dillonma committed Apr 25, 2023
1 parent fe600da commit f373aea
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 83 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: lehdr
Type: Package
Title: Grab Longitudinal Employer-Household Dynamics (LEHD) Flat Files
Version: 1.1.0
Version: 1.0.1
Authors@R: c(person(given="Jamaal", family="Green", role = c("cre","aut"), email="jamaal.green@gmail.com"),
person(given="Liming", family="Wang", role =c("aut"), email="lmwang@pdx.edu"),
person(given="Dillon", family="Mahmoudi", role =c("aut"), email="dillonm@umbc.edu"),
Expand Down Expand Up @@ -29,7 +29,7 @@ Suggests:
devtools,
pacman
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.1.2
URL: https://github.com/jamgreen/lehdr/
BugReports: https://github.com/jamgreen/lehdr/issues/
Config/testthat/edition: 3
25 changes: 9 additions & 16 deletions R/lehdr.R
Expand Up @@ -2,8 +2,8 @@
#' Download and load LODES data into a data frame (tibble)
#'
#' @param state US state abbreviation in lower case, can be a vector of states.
#' @param year Year of the LODES data, can be a vector of years.
#' @param lodes_type Table type, values can be origin-destination ("od"),
#' @param year year of the lodes data, can be a vector of years.
#' @param lodes_type table type, values can be origin-destination ("od"),
#' residential association ("rac"), or workplace association ("wac"). od
#' files give a home and destination census block for workers. Residential
#' files give job totals of worker home census blocks and workplace files
Expand All @@ -26,13 +26,10 @@
#' of state and workplace in the state of interest
#' @param agg_geo Aggregate to a geography other than Census Block (default).
#' Values can be "bg" for block group, "tract", "county", or "state".
#' @param download_dir Directory where LODES table will be downloaded.
#' @param download_dir Directory where lodes table will be downloaded.
#' @param use_cache Boolean indicating whether or not to check whether or not
#' the file had already been downloaded. Defaults to FALSE. Setting to TRUE
#' will allow lehdr to reuse existing files that were already downloaded.
#' @param lodes_ver Optional LODES version number as a character. Defaults to
#' the most recent version ("8") and accepts values "5", "7", or "8". LODES
#' "6" is not available for download.
#'
#' @description Download LODES OD, RAC, and WAC tables
#' @return a dataframe (tibble) of block or tract level LODES files
Expand Down Expand Up @@ -74,8 +71,7 @@ grab_lodes <- function(state, year,
agg_geo = c("block", "bg", "tract", "county", "state"),
state_part = c("","main","aux"),
download_dir = file.path(rappdirs::user_cache_dir(appname="lehdr")),
use_cache = FALSE, # Thanks Kyle Walker for this
lodes_ver = c("8","5","7")) {
use_cache = FALSE) { # Thanks Kyle Walker for this

if (length(state) > 1 | length(year) > 1) {
## Handle multiple states x years
Expand All @@ -86,9 +82,7 @@ grab_lodes <- function(state, year,
segment = segment,
agg_geo = agg_geo,
state_part = state_part,
download_dir = download_dir,
use_cache = use_cache,
lodes_ver = lodes_ver)
download_dir = download_dir)
)
return(dplyr::bind_rows(results))
}
Expand All @@ -102,7 +96,6 @@ grab_lodes <- function(state, year,
job_type <- match.arg(job_type, c(NULL, "JT00", "JT01", "JT02", "JT03", "JT04", "JT05"))
segment <- match.arg(segment, c(NULL, "S000", "SA01", "SA02", "SA03", "SE01", "SE02","SE03", "SI01", "SI02", "SI03"))
state_part <- match.arg(state_part, c("","main","aux"))
lodes_ver <- match.arg(lodes_ver, c("8","5","7"))

# Only proceed if use_cache is boolean
if(!is.logical(use_cache)) { stop("The use_cache paramater must be either TRUE or FALSE") }
Expand All @@ -120,14 +113,14 @@ grab_lodes <- function(state, year,
# Read LODES_types and set col_types
if (lodes_type == "od") {
# Set url for od
url <- glue::glue("https://lehd.ces.census.gov/data/lodes/LODES{lodes_ver}/{state}/{lodes_type}/{state}_{lodes_type}_{state_part}_{job_type}_{year}.csv.gz")
url <- glue::glue("https://lehd.ces.census.gov/data/lodes/LODES7/{state}/{lodes_type}/{state}_{lodes_type}_{state_part}_{job_type}_{year}.csv.gz")
# Set column types for od
col_types <- cols(w_geocode = col_character(),
h_geocode = col_character(),
createdate = col_character())
} else {
# Set url for rac/wac
url <- glue::glue("https://lehd.ces.census.gov/data/lodes/LODES{lodes_ver}/{state}/{lodes_type}/{state}_{lodes_type}_{segment}_{job_type}_{year}.csv.gz")
url <- glue::glue("https://lehd.ces.census.gov/data/lodes/LODES7/{state}/{lodes_type}/{state}_{lodes_type}_{segment}_{job_type}_{year}.csv.gz")

# Set column types for rac/wac -- h_ is home, w_ is work (from LODES)
if (lodes_type == "rac") {
Expand All @@ -142,8 +135,8 @@ grab_lodes <- function(state, year,
# On URL error, the likely culprit is the lack of state/year combination ...
httr::stop_for_status(httr::HEAD(url),
paste("retrieve data for this combination of state and year on LODES.",
"Please see the LEHD Technical Document for a list of available state/year.",
glue::glue("https://lehd.ces.census.gov/data/lodes/LODES{lodes_ver}/")
"Please see the most recent LEHD Technical Document for a list of available state/year.",
"https://lehd.ces.census.gov/data/lodes/LODES7/"
)
)

Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Expand Up @@ -33,7 +33,7 @@ knitr::opts_chunk$set(
-->
<!-- badges: end -->

**lehdr** (pronounced: _lee dur_ like a metric _litre_) is an R package that allows users to interface with the [Longitudinal and Employer-Household Dynamics (LEHD)](https://lehd.ces.census.gov/) Origin-Destination Employment Statistics (LODES) dataset returned as dataframes. LODES 5, 7, and 8 are currently supported. The package is continually in development and can be installed via CRAN.
**lehdr** (pronounced: _lee dur_ like a metric _litre_) is an R package that allows users to interface with the [Longitudinal and Employer-Household Dynamics (LEHD)](https://lehd.ces.census.gov/) Origin-Destination Employment Statistics (LODES) dataset returned as dataframes. The package is continually in development and can be installed via CRAN.

## Installation

Expand All @@ -51,7 +51,7 @@ devtools::install_github("jamgreen/lehdr")

## Usage

After loading the library, this first example pulls the Oregon (`state = "or"`) 2014 (`year = 2014`), origin-destination (`lodes_type = "od"`), all jobs including private primary, secondary, and Federal (`job_type = "JT01"`), all jobs across ages, earnings, and industry (`segment = "S000"`), aggregated at the Census Tract level rather than the default Census Block (`agg_geo = "tract"`). The package defaults to LODES8, but LODES5 and LODES7 are also supported with the `lodes_ver` argument (`lodes_ver = "8"`).
After loading the library, this first example pulls the Oregon (`state = "or"`) 2014 (`year = 2014`), origin-destination (`lodes_type = "od"`), all jobs including private primary, secondary, and Federal (`job_type = "JT01"`), all jobs across ages, earnings, and industry (`segment = "S000"`), aggregated at the Census Tract level rather than the default Census Block (`agg_geo = "tract"`).

```{r usage1, eval=FALSE}
library(lehdr)
Expand Down
8 changes: 3 additions & 5 deletions README.md
Expand Up @@ -25,8 +25,8 @@ downloads](https://cranlogs.r-pkg.org/badges/lehdr)](https://cran.r-project.org/
that allows users to interface with the [Longitudinal and
Employer-Household Dynamics (LEHD)](https://lehd.ces.census.gov/)
Origin-Destination Employment Statistics (LODES) dataset returned as
dataframes. LODES 5, 7, and 8 are currently supported. The package
is continually in development and can be installed via CRAN.
dataframes. The package is continually in development and can be
installed via CRAN.

## Installation

Expand All @@ -51,9 +51,7 @@ After loading the library, this first example pulls the Oregon
(`lodes_type = "od"`), all jobs including private primary, secondary,
and Federal (`job_type = "JT01"`), all jobs across ages, earnings, and
industry (`segment = "S000"`), aggregated at the Census Tract level
rather than the default Census Block (`agg_geo = "tract"`). The
package defaults to LODES8, but LODES5 and LODES7 are also supported
with the `lodes_ver` argument (`lodes_ver = "8"`).
rather than the default Census Block (`agg_geo = "tract"`).

``` r
library(lehdr)
Expand Down
13 changes: 4 additions & 9 deletions man/grab_lodes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 13 additions & 49 deletions tests/testthat/test-lehdr.R
@@ -1,80 +1,44 @@
test_that("test grab lodes od", {
expect_equal(grab_lodes(state = 'or', year = 2014, lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", agg_geo = "tract", lodes_ver = "7") %>%
segment = "SA01", state_part = "main", agg_geo = "tract") %>%
dim, c(223119, 14))
expect_equal(grab_lodes(state = 'or', year = 2014, lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", agg_geo = "tract", lodes_ver = "8") %>%
dim, c(261761, 14))
expect_equal(grab_lodes(state = 'or', year = 2009, lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", agg_geo = "tract", lodes_ver = "5") %>%
dim, c(185646, 14))
expect_equal(grab_lodes(state = "or", year = "2015", lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", lodes_ver = "7") %>%
segment = "SA01", state_part = "main" ) %>%
dim, c(1410831, 15))
expect_equal(grab_lodes(state = "or", year = "2015", lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", lodes_ver = "8") %>%
dim, c(1409076, 15))
expect_equal(grab_lodes(state = "or", year = "2009", lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", lodes_ver = "5") %>%
dim, c(1246010, 15))
})

test_that("test grab lodes rac", {
expect_equal(grab_lodes(state = 'or', year = 2014, lodes_type = "rac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "7") %>%
segment = "SA01", agg_geo = "tract") %>%
dim, c(834, 44))
expect_equal(grab_lodes(state = 'or', year = 2020, lodes_type = "rac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "8") %>%
dim, c(994, 44))
expect_equal(grab_lodes(state = "or", year = "2015", lodes_type = "rac", job_type = "JT01",
segment = "SA01", lodes_ver = "7") %>%
segment = "SA01") %>%
dim, c(60227, 45))
expect_equal(grab_lodes(state = "or", year = "2004", lodes_type = "rac", job_type = "JT01",
segment = "SA01", lodes_ver = "5") %>%
dim, c(53026, 43))
})

test_that("test grab lodes wac", {
expect_equal(grab_lodes(state = 'or', year = 2014, lodes_type = "wac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "7") %>%
segment = "SA01", agg_geo = "tract") %>%
dim, c(825, 54))
expect_equal(grab_lodes(state = 'or', year = 2009, lodes_type = "wac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "5") %>%
dim, c(754 , 42))
expect_equal(grab_lodes(state = "or", year = "2015", lodes_type = "wac", job_type = "JT01",
segment = "SA01", lodes_ver = "7") %>%
segment = "SA01") %>%
dim, c(23367, 55))
expect_equal(grab_lodes(state = "or", year = "2020", lodes_type = "wac", job_type = "JT01",
segment = "SA01", lodes_ver = "8") %>%
dim, c(24793, 55))
})

test_that("test grab lodes od for multiple states and years", {
expect_equal(grab_lodes(state = c('or', "ri"), year = c(2013, 2014), lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", agg_geo = "tract", lodes_ver = "7") %>%
segment = "SA01", state_part = "main", agg_geo = "tract") %>%
dim, c(511071, 14))
expect_equal(grab_lodes(state = c('wa', "ri"), year = c(2007, 2008), lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", agg_geo = "tract", lodes_ver = "5") %>%
dim, c(853294, 14))
expect_equal(grab_lodes(state = c('or', 'ri'), year = c(2013, 2014), lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", lodes_ver = "7") %>%
expect_equal(grab_lodes(state = c('or', "ri"), year = c(2013, 2014), lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main" ) %>%
dim, c(3326655, 15))
expect_equal(grab_lodes(state = c('or', 'md'), year = c(2013, 2020), lodes_type = "od", job_type = "JT01",
segment = "SA01", state_part = "main", lodes_ver = "8") %>%
dim, c(6384095, 15))
})

test_that("test grab lodes wac for multiple states and years", {
expect_equal(grab_lodes(state = c('or', 'ri'), year = c(2013, 2014), lodes_type = "wac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "7") %>%
expect_equal(grab_lodes(state = c('or', "ri"), year = c(2013, 2014), lodes_type = "wac", job_type = "JT01",
segment = "SA01", agg_geo = "tract") %>%
dim, c(2132, 54))
expect_equal(grab_lodes(state = c('or', 'ri'), year = c(2007, 2009), lodes_type = "wac", job_type = "JT01",
segment = "SA01", agg_geo = "tract", lodes_ver = "5") %>%
dim, c(1974, 42))
expect_equal(grab_lodes(state = c('or', 'ri'), year = c(2013, 2014), lodes_type = "wac", job_type = "JT01",
segment = "SA01", lodes_ver = "7") %>%
expect_equal(grab_lodes(state = c('or', "ri"), year = c(2013, 2014), lodes_type = "wac", job_type = "JT01",
segment = "SA01") %>%
dim, c(55307, 55))
expect_equal(grab_lodes(state = c('or', 'ri'), year = c(2017, 2018, 2019, 2020), lodes_type = "wac", job_type = "JT01",
segment = "SA01", lodes_ver = "8") %>%
dim, c(130857, 55))
})

0 comments on commit f373aea

Please sign in to comment.