@@ -104,20 +104,6 @@ format_address <- function(df, fields) {
104104# QA Checks --------------------------------------------------------------------
105105# functions called by reverse_geo() and/or geo()
106106
107- check_api_options <- function (api_options , func_name ) {
108- for (param in names(api_options )) {
109- if (! param %in% c(" cascade_flag" , " init" , names(pkg.globals $ default_api_options ))) {
110- stop(
111- paste0(
112- " Invalid parameter " , ' "' , param , ' "' ,
113- " used in the api_options argument. See ?" , func_name
114- ),
115- call. = FALSE
116- )
117- }
118- }
119- }
120-
121107# check the data type of an address argument - called by geo() function
122108# should not be a matrix, class, or dataframe for instance
123109# allow factor since it could be coerced to a datatype by address handler function
@@ -384,22 +370,46 @@ flatten_override_warning <- function(flatten, method, reverse, batch) {
384370 }
385371}
386372
373+
374+ # TODO: combine these two functions
375+
376+ check_api_options <- function (api_options , func_name ) {
377+ for (param in names(api_options )) {
378+ if (! param %in% c(" cascade_flag" , " init" , names(pkg.globals $ default_api_options ))) {
379+ stop(
380+ paste0(
381+ " Invalid parameter " , ' "' , param , ' "' ,
382+ " used in the api_options argument. See ?" , func_name
383+ ),
384+ call. = FALSE
385+ )
386+ }
387+ }
388+ }
389+
387390# throw error if method and a specified api_option is mismatched
388391# ie. method='census' and api_options(list(geocodio_hipaa=TRUE))
389392check_method_api_options_mismatch <- function (method , api_options , reverse = FALSE ) {
390393 # cycle through the api options specified (except for init)
391394 if (api_options $ init == TRUE ) {
392- for (api_opt in names(api_options )[! names(api_options ) %in% c(' init' )]) {
395+ bad_api_args <- c()
396+ for (api_opt in names(api_options )[! names(api_options ) %in% c(' cascade_flag' , ' init' )]) {
393397 # extract method name from api_option
394398 api_opt_method <- strsplit(api_opt , " _" )[[1 ]][[1 ]]
395399
400+ # if mismatch then add offending arg to vector
396401 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+ bad_api_args <- c(bad_api_args , api_opt )
402403 }
403404 }
405+
406+ if (length(bad_api_args ) != 0 ) {
407+ stop(
408+ ' method="' , method , ' " is not compatible with the specified api_options parameter(s):\n\n ' ,
409+ paste0(bad_api_args , sep = " " ), " \n\n " ,
410+ ' See ?' , if (reverse == TRUE ) " reverse_geo" else " geo" ,
411+ call. = FALSE
412+ )
413+ }
404414 }
405415}
0 commit comments