Two fixes for bugs in `route`
- Dominant language
- R
- Stars
- 778
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
Hey @dkahle
I forked your library a while back to deal with some problems I was working with, and my library has now diverged from yours a fair amount, but there are a couple little things I wanted to suggest might be worth integrating into your library to deal with bugs.
**Strip Reverse Geocode**
`route` current reverse geocodes lat-longs. This is slow and can cause problems -- for example, I had a lat-long that reverse geocoded to an "unnamed street, lowell, indiana". When this was then fed back into google maps, it coded to a street named lowell in Colorado. Easier/ safer is to just feed lat-long in directly. So replace lines 59 - 69 with: (note order flip for reverse compatibility -- google maps likes lat-long for strings, not x-y:
if(is.numeric(from) && length(from) == 2) {
from <- paste(from[2], from[1], sep=",")
}
stopifnot(is.character(from))
if(is.numeric(to) && length(to) == 2) {
to <- paste(to[2], to[1], sep=",")
}
stopifnot(is.character(to))
Also, the script doesn't currently sanitize for ampersands, which screws with how google parses APIs. Doesn't raise an error, just leads to wrong locations. So I added the following before url creation:
# Clean ampersands in strings -- cause geocode errors.
if (is.character(from)) {
sub("&", " and ", from)
stopifnot(!grep('&', from))
}
if (is.character(to)) {
sub("&", " and ", to)
stopifnot(!grep('&', to))
}
Anyway, thought might be useful to others.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.