Skip to content

Commit

Permalink
Simplify inner_join() in get_trip_geometry()
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Feb 27, 2023
1 parent e215f9c commit 14b2dc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
11 changes: 8 additions & 3 deletions R/spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ get_trip_geometry <- function(gtfs_sf_obj, trip_ids) {
}

trips = gtfs_sf_obj$trips %>% filter(trip_id %in% trip_ids)
trips_shapes = suppress_matches_multiple_warning(
dplyr::inner_join(gtfs_sf_obj$shapes, trips, by = "shape_id")
)

if (utils::packageVersion("dplyr") >= "1.1.0.9000") {
trips_shapes = dplyr::inner_join(gtfs_sf_obj$shapes, trips, by = "shape_id")
} else {
# TODO: Remove after dplyr 1.1.1 is released
trips_shapes = dplyr::inner_join(gtfs_sf_obj$shapes, trips, by = "shape_id", multiple = "all")
}

return(trips_shapes)
}

Expand Down
13 changes: 0 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,3 @@ na_to_empty_strings = function(gtfs_obj) {
df
})
}

# TODO: Remove after dplyr 1.1.0 is released and use `multiple = "all"` instead
suppress_matches_multiple_warning <- function(expr) {
handler_matches_multiple <- function(cnd) {
if (inherits(cnd, "dplyr_warning_join_matches_multiple")) {
restart <- findRestart("muffleWarning")
if (!is.null(restart)) {
invokeRestart(restart)
}
}
}
withCallingHandlers(expr, warning = handler_matches_multiple)
}

0 comments on commit 14b2dc8

Please sign in to comment.