knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
fipio
is a lightweight package that makes it easy to get information about a US FIPS code.
You can install the released version of fipio
from CRAN with:
install.packages("fipio")
or the development version with pak
or remotes
:
# Using `pak` pak::pkg_install("program--/fipio") # Using `remotes` remotes::install_github("program--/fipio")
fipio
makes it easy to get information about a US FIPS code.
Let's answer a few questions that might come up if you have a FIPS code:
fip <- "37129" # What state is `37129` in? fipio::fips_state(fip) # Alternatively, you can use the state FIPS code by itself fipio::fips_state("37") # What about the state abbreviation? fipio::fips_abbr(fip) # What county is `37129`? fipio::fips_county(fip) # It'd be nice to have this all in a data.frame... fipio::fips_metadata(fip) # And the metadata for the state by itself... fipio::fips_metadata("37")
sf
fipio
also includes functions that support geometry for FIPS codes. This requires
sfheaders
at the very least to get an sf
-compatible geometry object back.
library(sf, quietly = TRUE)
# I'm doing spatial work, what's the geometry of `37129`? fipio::fips_geometry(fip) # What if I need it with my other metadata? fipio::fips_metadata(fip, geometry = TRUE)
fipio
functions are inherently vectorized, so you can use them with vectors of FIPS codes easily:
fips <- c("37129", "44001", "48115") fipio::fips_state(fips) fipio::fips_abbr(fips) fipio::fips_county(fips) fipio::fips_metadata(fips) fipio::fips_geometry(fips)
fipio
contains the ability to locate the FIPS code(s) for a set of coordinates (in WGS84
/EPSG:4326
):
# With a single set of coordinates fipio::coords_to_fips(x = -119.8696, y = 34.4184) # Vectorized fipio::coords_to_fips( x = c(-81.4980534549709, -81.1249425046948), y = c(36.4314781444978, 36.4911893240597) ) # With a `data.frame` or `matrix` fipio::coords_to_fips( x = data.frame( X = c(-81.4980534549709, -81.1249425046948), Y = c(36.4314781444978, 36.4911893240597) ), coords = c("X", "Y") ) # With an `sfg` object fipio::coords_to_fips( x = sf::st_point(c(-81.4980534549709, 36.4314781444978)), dim = "XY" ) # With an `sf` object fipio::coords_to_fips( x = sf::st_as_sf( data.frame(X = c(-81.4980534549709, -81.1249425046948), Y = c(36.4314781444978, 36.4911893240597)), coords = c("X", "Y"), crs = 4326 ) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.