-
Notifications
You must be signed in to change notification settings - Fork 45
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
key
parameter in add_osm_feature can be negated
#297
Conversation
Broken tests fixed with #295 |
# Conflicts: # R/opq.R
Ready for review @mpadge |
Thanks as always @jmaspons, but I have to admit that i'm unsure about this one. One of the abiding aims of this package has always been to place as little demand on the overpass server as possible. The simple ability to replace
Does that make sense? |
And this is really interesting: f1 <- function (key) {
ifelse (substring (key, 1, 1) == "!",
sprintf ('[!"%s"]', substring (key, 2, nchar (key))),
sprintf ('["%s"]', key))
}
f2 <- function (key) {
ifelse (grepl ("^\\!", key),
sprintf ('[!"%s"]', substring (key, 2, nchar (key))),
sprintf ('["%s"]', key))
}
f3 <- function (key) {
ifelse (grepl ("^\\!", key),
sprintf ('[!"%s"]', gsub ("^\\!", "", key)),
sprintf ('["%s"]', key))
}
key <- "!key"
bench::mark (f1 (key), f2 (key), f3 (key)) [, 1:3]
#> # A tibble: 3 × 3
#> expression min median
#> <bch:expr> <bch:tm> <bch:tm>
#> 1 f1(key) 12.2µs 14.6µs
#> 2 f2(key) 15.9µs 19.1µs
#> 3 f3(key) 20µs 24.2µs Created on 2023-01-19 with reprex v2.0.2 I probably would have been tempted to use regexes, but your approach is obviously superior. Nice, and good (for me at least) to keep in mind. |
The key negation should always be accompanied by some other filters. At least that's the use key I'm thinking in.
Which OSM objects with
Is a warning in the docs enough? Otherwise, I think the best place is during the osmdata_* calls when the query is completed to check if a negated key is the only filter and maybe asking the user if she wants to carry on with the query |
For the grep vs substring thing, I just replicate the same pattern as for negate values. So blame on you or whoever implement that part (applause in this case :)). I tend to go for grep as a first option as well |
These are great - could you please add them to the
That's also a good idea, but the package currently does not have any interactive components, and it'd be kind of nice to keep it that way. (I commonly perform huge batch jobs which call various |
Warning and examples added |
Can you merge this, @mpadge ? |
Sorry, been super-busy doing other things. Yes, of course I'll merge. Thank you so much for all of these continuing contributions! |
Same behaviour as the
value
parameter