-
Notifications
You must be signed in to change notification settings - Fork 21
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
Unable to pass column names to tidygeocoder::geocode()
with wrapper function
#189
Comments
Hi @elipousson, there might be a more elegant solution than this but if you are OK using named arguments then this works for me: tbl <- tibble::as_tibble(
data.frame(
"Addr" = "1 N. Charles St, Baltimore, MD 21201"
)
)
test_geocode <- function(.tbl, ...) {
tidygeocoder::geocode(
.tbl = .tbl,
...
)
}
test_geocode(tbl, address="Addr")
#> Passing 1 address to the Nominatim single address geocoder
#> Query completed in: 1 seconds
#> # A tibble: 1 × 3
#> Addr lat long
#> <chr> <dbl> <dbl>
#> 1 1 N. Charles St, Baltimore, MD 21201 39.3 -76.6 Created on 2023-05-01 with reprex v2.0.2 I'd have to do a little more digging to figure out why your original code is behaving that way, but I suspect it has to do with how the arguments are processed in geocode(). There's some logic here that allows the address argument to be passed in either quoted or unquoted form (ie. Line 90 in bd51794
|
I think the issue is the way that tbl <- tibble::as_tibble(
data.frame(
"Addr" = "1 N. Charles St, Baltimore, MD 21201"
)
)
test_geocode <- function(.tbl, ...) {
withr::local_environment(
parent.frame(),
tidygeocoder::geocode(
.tbl = .tbl,
...,
)
)
}
test_geocode(tbl, "Addr")
#> Passing 1 address to the Nominatim single address geocoder
#> Query completed in: 1 seconds
#> Error in if (pos == 1L) stop("'pos=1' is not possible and has been warned about for years"): the condition has length > 1 Created on 2023-05-01 with reprex v2.0.2 |
I'm not sure whether this is a bug report or feature request but, given the way
tidygeocoder::geocode()
handles the evaluation of argument names, I can't figure out how to pass a variable. If there is a way to do this with rlang that doesn't require changes to tidygeocoder, I'd welcome any advice you can share. If not, I'd love to see an option that allowstidygeocoder::geocode()
to work with this type of wrapper function.Created on 2023-05-01 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: