Skip to content

Commit 725be64

Browse files
author
Jesse Cambon
committed
streamline api_options parameter checking
1 parent 967dec4 commit 725be64

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

R/geo.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ geo <-
267267

268268
# Check parameter arguments --------------------------------------------------------
269269

270-
check_api_options(method, api_options, reverse = FALSE)
270+
check_api_options(method, api_options, FALSE, return_addresses)
271271

272272
# Check argument inputs
273273
if (is.null(address) && is.null(street) && is.null(city) && is.null(county) && is.null(state) && is.null(postalcode) && is.null(country)) {
@@ -293,11 +293,7 @@ geo <-
293293
is.logical(full_results), is.logical(unique_only), is.logical(return_addresses),
294294
is.null(batch_limit_error) || is.logical(batch_limit_error), is.logical(progress_bar), is.logical(quiet),
295295
is.numeric(timeout), timeout >= 0,
296-
is.list(custom_query),
297-
is.null(api_options[["mapbox_permanent"]]) || is.logical(api_options[["mapbox_permanent"]]),
298-
is.null(api_options[["here_request_id"]]) || is.character(api_options[["here_request_id"]]),
299-
is.null(api_options[["mapquest_open"]]) || is.logical(api_options[["mapquest_open"]]),
300-
is.null(api_options[["geocodio_hipaa"]]) || is.logical(api_options[["geocodio_hipaa"]])
296+
is.list(custom_query)
301297
)
302298

303299
check_verbose_quiet(verbose, quiet, reverse = FALSE)

R/input_handling.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# utility function for packaging either lat longs or address data
77
# takes a dataframe input
88
# cords = TRUE if processing coordinates
9+
# note that reverse_geo() converts lat and long into numeric before passing to this function
910
package_inputs <- function(input_orig, coords = FALSE) {
1011
input_colnames <- names(input_orig) # store column names
1112

R/reverse_geo.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,13 @@ reverse_geo <-
185185
is.logical(verbose), is.logical(no_query), is.logical(flatten),
186186
is.logical(full_results), is.logical(unique_only), is.logical(progress_bar),
187187
is.logical(quiet),
188-
is.list(custom_query),
189-
is.null(api_options[["mapbox_permanent"]]) || is.logical(api_options[["mapbox_permanent"]]),
190-
is.null(api_options[["here_request_id"]]) || is.character(api_options[["here_request_id"]]),
191-
is.null(api_options[["mapquest_open"]]) || is.logical(api_options[["mapquest_open"]]),
192-
is.null(api_options[["geocodio_hipaa"]]) || is.logical(api_options[["geocodio_hipaa"]])
188+
is.list(custom_query)
193189
)
194190

195191
check_verbose_quiet(verbose, quiet, reverse = FALSE)
196192

197193
# Check method argument
198-
check_api_options(method, api_options, reverse = TRUE)
194+
check_api_options(method, api_options, TRUE, return_coords)
199195
check_method(method, reverse = TRUE, mode, reverse_batch_func_map)
200196

201197
if (length(lat) != length(long)) stop("Lengths of lat and long must be equal.", call. = FALSE)
@@ -288,8 +284,6 @@ reverse_geo <-
288284
))
289285
}
290286

291-
if (method == "here") check_here_return_input(api_options[["here_request_id"]], return_coords, reverse = TRUE)
292-
293287
# Enforce batch limit if needed
294288
if (num_unique_coords > batch_limit) {
295289
stop(paste0(

R/utils.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,19 @@ apply_api_options_defaults <- function(method, api_options) {
382382

383383
# throw error if method and a specified api_option is mismatched
384384
# ie. method='census' and api_options(list(geocodio_hipaa=TRUE))
385-
check_api_options <- function(method, api_options, reverse=FALSE) {
385+
# return_inputs : return_addresses for geo() or return_inputs for reverse_geo()
386+
check_api_options <- function(method, api_options, reverse, return_inputs) {
387+
388+
stopifnot(
389+
is.null(api_options[["mapbox_permanent"]]) || is.logical(api_options[["mapbox_permanent"]]),
390+
is.null(api_options[["here_request_id"]]) || is.character(api_options[["here_request_id"]]),
391+
is.null(api_options[["mapquest_open"]]) || is.logical(api_options[["mapquest_open"]]),
392+
is.null(api_options[["geocodio_hipaa"]]) || is.logical(api_options[["geocodio_hipaa"]])
393+
)
394+
395+
if (method == "here") check_here_return_input(api_options[["here_request_id"]], return_inputs, reverse = reverse)
396+
397+
386398
# cycle through the api options specified (except for init)
387399
if (api_options$init == TRUE) {
388400
api_method_mismatch_args <- c() # store mismatch api_options here
@@ -404,7 +416,6 @@ check_api_options <- function(method, api_options, reverse=FALSE) {
404416
}
405417
} # end loop
406418

407-
408419
# error message for bad api arguments
409420
if (length(api_bad_args) != 0) {
410421
error_message <- c(error_message,

0 commit comments

Comments
 (0)