-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
141 lines (107 loc) · 3.62 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# fipio <a href="https://github.com/program--/fipio"><img src="man/figures/logo.png" align="right" width="25%"/></a>
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/fipio)](https://CRAN.R-project.org/package=fipio)
[![CRAN downloads](https://cranlogs.r-pkg.org/badges/fipio)](https://CRAN.R-project.org/package=fipio)
[![codecov](https://codecov.io/gh/program--/fipio/graph/badge.svg?token=1ODDHARQM1)](https://app.codecov.io/gh/program--/fipio)
[![R-CMD-check](https://github.com/program--/fipio/workflows/R-CMD-check/badge.svg)](https://github.com/program--/fipio/actions)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/license/mit/)
<!-- badges: end -->
`fipio` is a **lightweight** package that makes it easy to get information about a US FIPS code.
## Installation
You can install the released version of `fipio` from [CRAN](https://cran.r-project.org/package=fipio) with:
``` r
install.packages("fipio")
```
or the development version with `pak` or `remotes`:
``` r
# Using `pak`
pak::pkg_install("program--/fipio")
# Using `remotes`
remotes::install_github("program--/fipio")
```
## Usage
`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:
```{r}
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")
```
### With `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.
```{r, include = FALSE}
library(sf, quietly = TRUE)
```
```{r}
# 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)
```
### Vectorized
`fipio` functions are inherently vectorized, so you can use them with vectors of FIPS codes easily:
```{r}
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)
```
### Reverse Geolocate Coordinates to FIPS
`fipio` contains the ability to locate the FIPS code(s) for a set of coordinates (in `WGS84`/`EPSG:4326`):
```{r}
# 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
)
)
```