Chapter 3 Usage
oepsData is centered around two functions: load_oeps_dictionary, which loads a basic data dictionary; and load_oeps, which directly loads OEPS data. We expect that most users will start by calling load_oeps_dictionary to look at what data is available at their desired analysis scale, followed by calling load_oeps to actually load the data.
3.1 load_oeps_dictionary
load_oeps_dictionary takes one argument:
scaleOne of “tract”, “zcta”, “county”, or “state”
It returns the data dictionary (stored as a data.frame).
If you are working in RStudio, we recommend browsing the dictionary through the View command:
Here in the docs we can preview it directly:
3.2 load_oeps
We might find that we’re interested in the 1990 state data. We can load that data and its geometries using load_oeps, which accepts the following arguments:
scaleThe scale of analysis. One of “tract”, “zcta”, “county”, or “state”yearThe release year for the data. One of 1980, 1990, 2000, 2010, or 2018.themesThe theme to pull data for. One of ’Geography”, “Social”, “Environment”, “Economic”, “Policy”, “Composite”, or “All”. DefaultsAll.statesA string or vector of strings specifying which states to pull data for, either as FIPS codes or names. Ignored when scale is in ZCTA. DefaultsNone.countiesA string or vector of strings specifying which counties to pull data for, either as FIPS or names. Ignored for ZCTA, and must be specified alongsidestates. DefaultsNone.tidyBoolean specifying whether to return data in tidy format; defaults toFALSE.geometryBoolean specifying whether to pull geometries for the dataset. DefaultsFALSEcacheBoolean specifying whether to use cahced geometries or not. DefaultsTRUE. See A note on caching for more information.
Which lets us operate on the data as we desire. For instance, we can make a simple map:
library(tmap)
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.8.5, PROJ 9.5.1; sf_use_s2() is TRUE
# reproject to a better display CRS
states_1990 <- st_transform(states_1990, "ESRI:102004")
tm_shape(states_1990) +
tm_fill("NoHsP", style="jenks") +
tm_borders(alpha=0.05) +
tm_layout(main.title = "Population over 25 without a high school degree")
#>
#> ── tmap v3 code detected ───────────────────────────────────────────────────────
#> [v3->v4] `tm_fill()`: instead of `style = "jenks"`, use fill.scale =
#> `tm_scale_intervals()`.
#> ℹ Migrate the argument(s) 'style' to 'tm_scale_intervals(<HERE>)'
#> [v3->v4] `tm_borders()`: use 'fill' for the fill color of polygons/symbols
#> (instead of 'col'), and 'col' for the outlines (instead of 'border.col').
#> [v3->v4] `tm_borders()`: use `fill_alpha` instead of `alpha`.
#> [v3->v4] `tm_layout()`: use `tm_title()` instead of `tm_layout(main.title = )`
See Examples for many more demonstrations of how you can use this function.
3.2.1 A note on caching
oepsData pulls its data from online repositories, primarily GitHub. This can lead to issues for users operating on slow internet, for whom load times can be long for larger datasets, or for users who anticipate needing the package when entirely offline.
To help minimize these issues, oepsData caches, or saves a local copy of, data loaded by load_oeps on its first load. Any later usage of the dataset will be pulled from the local cache.
Additionally, oepsData offers a few commands can help maintain caches:
cache_geometriesandcache_oeps_tableswill pre-cache all tables and geometries (it will overwrite existing cache content in the process).clear_cachedeletes all cached data.cache_dirreturns the directory of theoepsDatacache.
Users who want to avoid using cached data and instead download data fresh every time can set cache=FALSE when calling load_oeps.