Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve coords_to_fips order list error #16

Merged
merged 3 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ jobs:
# Use 3.6 to trigger usage of RTools35
- {os: windows-latest, r: '3.6'}

# Use older ubuntu to maximise backward compatibility
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-18.04, r: 'oldrel-1'}
- {os: ubuntu-18.04, r: 'oldrel-2'}
- {os: ubuntu-18.04, r: 'oldrel-3'}
- {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'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-pandoc@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
11 changes: 7 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# fipio 1.1.1.9000

- Fixed `coords_to_fips()` throwing `order` error due to `ret_index` being a list ([#15](https://github.com/program--/fipio/issues/15))
- Return documentation back to linking to https://github.com/program-- instead of UFOKN's GitHub org.

# fipio 1.1.1

- Added [Mike Johnson](https://github.com/mikejohnson51) to `DESCRIPTION`.
- Fixed `coords_to_fips()` throwing error in some edge cases ([#11](https://github.com/UFOKN/fipio/issues/11)).
- Fixed `as_fips()` throwing error for unknown states. ([#10](https://github.com/UFOKN/fipio/issues/10)).
- Fixed `as_fips()` edge case throwing error ([#13](https://github.com/UFOKN/fipio/pull/13)).
- Fixed `coords_to_fips()` throwing error in some edge cases ([#11](https://github.com/program--/fipio/issues/11)).
- Fixed `as_fips()` throwing error for unknown states. ([#10](https://github.com/program--/fipio/issues/10)).
- Fixed `as_fips()` edge case throwing error ([#13](https://github.com/program--/fipio/pull/13)).

# fipio 1.1.0

Expand All @@ -31,4 +34,4 @@
- `fips_state()` - Gets state name.
- `fips_county()` - Gets county name.
- `fips_geometry()` - Gets geometry.
- `fips_metadata()` - Gets the information above as a `data.frame`.
- `fips_metadata()` - Gets the information above as a `data.frame`.
17 changes: 12 additions & 5 deletions R/geolocate.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ coords_to_fips.numeric <- function(x, y, ...) {
lookup_geometry <- .geometry_fips[county_fips]
rm(county_fips)

# Filter out geometries by bounding box,
# like a spatial index
intersected <- which(sapply(
lookup_geometry,
FUN = function(g) {
Expand All @@ -84,21 +86,26 @@ coords_to_fips.numeric <- function(x, y, ...) {
USE.NAMES = FALSE
))

# Get fips and geometry based on `intersected`
lookup_fips <- lookup_fips[intersected]
lookup_geometry <- lookup_geometry[intersected]

ret_index <- sapply(
ret_index <- lapply(
lookup_geometry,
FUN = .intersects,
x = x,
y = y,
USE.NAMES = FALSE
y = y
)

ret_value <- .pad0(lookup_fips)[!is.na(ret_index)]
ret_index <- ret_index[!is.na(ret_index)]

rm(lookup_fips, lookup_geometry)

ret_value[order(ret_index)]
}
result <- character(length(x))
for (ind in seq_along(ret_value)) {
result[ret_index[[ind]]] <- ret_value[ind]
}

result
}
12 changes: 6 additions & 6 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ knitr::opts_chunk$set(
)
```

# fipio <a href="https://github.com/UFOKN/fipio"><img src="man/figures/logo.png" align="right" width="25%"/></a>
# 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/UFOKN/fipio/branch/master/graph/badge.svg)](https://app.codecov.io/gh/UFOKN/fipio)
[![R-CMD-check](https://github.com/UFOKN/fipio/workflows/R-CMD-check/badge.svg)](https://github.com/UFOKN/fipio/actions)
[![codecov](https://codecov.io/gh/program--/fipio/branch/master/graph/badge.svg)](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/licenses/MIT)
<!-- badges: end -->

Expand All @@ -36,10 +36,10 @@ install.packages("fipio")
or the development version with `pak` or `remotes`:
``` r
# Using `pak`
pak::pkg_install("UFOKN/fipio")
pak::pkg_install("program--/fipio")

# Using `remotes`
remotes::install_github("UFOKN/fipio")
remotes::install_github("program--/fipio")
```

## Usage
Expand Down Expand Up @@ -138,4 +138,4 @@ fipio::coords_to_fips(
crs = 4326
)
)
```
```
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# fipio <a href="https://github.com/UFOKN/fipio"><img src="man/figures/logo.png" align="right" width="25%"/></a>
# 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/UFOKN/fipio/branch/master/graph/badge.svg)](https://app.codecov.io/gh/UFOKN/fipio)
[![R-CMD-check](https://github.com/UFOKN/fipio/workflows/R-CMD-check/badge.svg)](https://github.com/UFOKN/fipio/actions)
[![codecov](https://codecov.io/gh/program--/fipio/branch/master/graph/badge.svg)](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/licenses/MIT)
<!-- badges: end -->
Expand All @@ -31,10 +31,10 @@ or the development version with `pak` or `remotes`:

``` r
# Using `pak`
pak::pkg_install("UFOKN/fipio")
pak::pkg_install("program--/fipio")

# Using `remotes`
remotes::install_github("UFOKN/fipio")
remotes::install_github("program--/fipio")
```

## Usage
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-fipio.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ testthat::test_that("as_fips edge cases", {
# Coverage for match(), .has_fastmatch(), .onLoad()
testthat::test_that("`fmatch` is assigned to `match` if it is installed", {
testthat::skip_if(!requireNamespace("mockery", quietly = TRUE))
testthat::skip_if(!requireNamespace("fastmatch", quietly = TRUE))
m <- mockery::mock(FALSE, TRUE)
mockery::stub(expect_match_assignment, ".has_fastmatch", m)

Expand Down Expand Up @@ -238,4 +239,4 @@ testthat::test_that("fipio returns NA for nonexistant states/counties", {
),
c("44001", NA_character_, "06001")
)
})
})