Skip to content

Commit af9b3c2

Browse files
author
Jesse Cambon
committed
method api_options conflict error
1 parent 79fd585 commit af9b3c2

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Changed the default `min_time` (minimum seconds elapsed per query) value to 1 (60 queries per minute) for the Location IQ service ([#166](https://github.com/jessecambon/tidygeocoder/issues/166)).
44
- Updated default Geocodio API URL from version 1.6 to 1.7.
55
- Fixed code and documentation that incorrectly referred to `mapquest_open` as `mapbox_open`.
6+
- An error is now thrown if an `api_options` parameter is not compatible with the specified `method`.
67
- A message is now displayed warning that `flatten=FALSE` is ignored for Geocodio and Mapquest (the output of these services requires flattening to avoid errors).
78

89
# tidygeocoder 1.0.5

R/geo.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ geo <-
238238
api_options[["here_request_id"]] <- here_request_id
239239
}
240240
}
241-
241+
242+
# check for method / api_options mismatch
243+
check_method_api_options_mismatch(method, api_options, FALSE)
244+
242245
# apply api options defaults for options not specified by the user
243246
api_options <- apply_api_options_defaults(api_options)
244247

R/reverse_geo.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ reverse_geo <-
169169
here_request_id <- NULL
170170
}
171171
}
172+
173+
# check for method / api_options mismatch
174+
check_method_api_options_mismatch(method, api_options, TRUE)
172175

173176
# apply api options defaults for options not specified by the user
174177
api_options <- apply_api_options_defaults(api_options)

R/utils.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,23 @@ flatten_override_warning <- function(flatten, method, reverse, batch) {
383383
))
384384
}
385385
}
386+
387+
# throw error if method and a specified api_option is mismatched
388+
# ie. method='census' and api_options(list(geocodio_hipaa=TRUE))
389+
check_method_api_options_mismatch <- function(method, api_options, reverse=FALSE) {
390+
# cycle through the api options specified (except for init)
391+
if (api_options$init == TRUE) {
392+
for (api_opt in names(api_options)[!names(api_options) %in% c('init')]) {
393+
# extract method name from api_option
394+
api_opt_method <- strsplit(api_opt, "_")[[1]][[1]]
395+
396+
if (api_opt_method != method) {
397+
stop(
398+
'method="', method, '" is not meant for use with api_options=list(', api_opt, ')\n',
399+
'See ?', if (reverse == TRUE) "reverse_geo" else "geo",
400+
call. = FALSE
401+
)
402+
}
403+
}
404+
}
405+
}

0 commit comments

Comments
 (0)