Skip to content

Commit 145e4a5

Browse files
author
Jesse Cambon
committed
api options check function incomplete
1 parent af9b3c2 commit 145e4a5

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

R/input_handling.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ package_inputs <- function(input_orig, coords = FALSE) {
1313

1414
# limit lat/longs in unique dataset to possible values
1515
if (coords == TRUE) {
16-
input_unique$lat[(input_unique$lat > 90 | input_unique$lat < -90)] <- NA
17-
input_unique$long[(input_unique$long > 180 | input_unique$long < -180)] <- NA
16+
input_unique$lat[(input_unique$lat > 90 | input_unique$lat < -90)] <- as.numeric(NA)
17+
input_unique$long[(input_unique$long > 180 | input_unique$long < -180)] <- as.numeric(NA)
1818

1919
# If lat is NA then make long NA and vice versa (ie. don't pass coordinate if
2020
# only one value exists)
21-
input_unique$lat <- ifelse(is.na(input_unique$long), NA, input_unique$lat)
22-
input_unique$long <- ifelse(is.na(input_unique$lat), NA, input_unique$long)
21+
input_unique$lat <- ifelse(is.na(input_unique$long), as.numeric(NA), input_unique$lat)
22+
input_unique$long <- ifelse(is.na(input_unique$lat), as.numeric(NA), input_unique$long)
2323
}
2424

2525
# remove rows that are entirely blank or NA

R/results_processing.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extract_results <- function(method, response, full_results = TRUE, flatten = TRU
108108

109109
# add prefix to variable names that likely could be in our input dataset
110110
# to avoid variable name overlap
111-
for (var in c("address", "street", "city", "county", "state", "postalcode", "postcode", "country")) {
111+
for (var in c(pkg.globals$address_arg_names, "postcode")) {
112112
if (var %in% names(results)) {
113113
names(results)[names(results) == var] <- paste0(method, "_", var)
114114
}
@@ -177,7 +177,7 @@ extract_reverse_results <- function(method, response, full_results = TRUE, flatt
177177
"geoapify" = response$features$properties["formatted"]
178178
)
179179

180-
# Return NA if data is not empty or not valid (cannot be turned into a dataframe)
180+
# Return NA if data is empty or not valid (cannot be turned into a dataframe)
181181
if (is.null(names(address)) | all(sapply(address, is.null)) | length(address) == 0) {
182182
return(NA_result)
183183
}

R/reverse_geo.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ reverse_geo <-
197197
check_verbose_quiet(verbose, quiet, reverse = FALSE)
198198

199199
# Check method argument
200-
201200
check_api_options(api_options, "reverse_geo")
202201
check_method(method, reverse = TRUE, mode, reverse_batch_func_map)
203202

R/utils.R

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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))
389392
check_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

Comments
 (0)