|
1 | | -.check_addresses <- function(addresses) { |
2 | | - if (!is.character(addresses)) { |
| 1 | +.check_character <- function(text) { |
| 2 | + if (!is.character(text) & !is.null(text)) { |
3 | 3 | stop(sprintf( |
4 | 4 | "'%s' must be a 'character' vector.", |
5 | | - deparse(substitute(addresses)) |
| 5 | + deparse(substitute(text)) |
6 | 6 | )) |
7 | 7 | } |
8 | | - if (any(is.na(addresses))) { |
| 8 | + if (any(is.na(text))) { |
9 | 9 | stop(sprintf( |
10 | 10 | "'%s' contains NAs.", |
11 | | - deparse(substitute(addresses)) |
| 11 | + deparse(substitute(text)) |
12 | 12 | )) |
13 | 13 | } |
14 | | - if ("" %in% gsub(" ", "", addresses)) { |
| 14 | + if ("" %in% gsub(" ", "", text)) { |
15 | 15 | stop(sprintf( |
16 | 16 | "'%s' contains empty strings.", |
17 | | - deparse(substitute(addresses)) |
| 17 | + deparse(substitute(text)) |
18 | 18 | )) |
19 | 19 | } |
20 | 20 | } |
|
41 | 41 | } |
42 | 42 |
|
43 | 43 | .check_polygon <- function(polygon) { |
44 | | - if (!"sf" %in% class(polygon)) { |
45 | | - stop(sprintf( |
46 | | - "'%s' must be an sf object.", |
47 | | - deparse(substitute(polygon)) |
48 | | - )) |
49 | | - } |
50 | | - if (any(sf::st_is_empty(polygon))) { |
51 | | - stop(sprintf( |
52 | | - "'%s' has empty entries in the geometry column.", |
53 | | - deparse(substitute(polygon)) |
54 | | - )) |
55 | | - } |
56 | | - if (!"sf" %in% class(polygon) | |
57 | | - any(!( |
58 | | - sf::st_geometry_type(polygon) %in% c("POLYGON", "MULTIPOLYGON") |
59 | | - ))) { |
60 | | - stop(sprintf( |
61 | | - "'%s' must be an sf object with geometry type 'POLYGON' or 'MULTIPOLYGON'.", |
62 | | - deparse(substitute(polygon)) |
63 | | - )) |
| 44 | + if (!is.null(polygon)) { |
| 45 | + if (!"sf" %in% class(polygon)) { |
| 46 | + stop(sprintf( |
| 47 | + "'%s' must be an sf object.", |
| 48 | + deparse(substitute(polygon)) |
| 49 | + )) |
| 50 | + } |
| 51 | + if (any(sf::st_is_empty(polygon))) { |
| 52 | + stop(sprintf( |
| 53 | + "'%s' has empty entries in the geometry column.", |
| 54 | + deparse(substitute(polygon)) |
| 55 | + )) |
| 56 | + } |
| 57 | + if (!"sf" %in% class(polygon) | |
| 58 | + any(!( |
| 59 | + sf::st_geometry_type(polygon) %in% c("POLYGON", "MULTIPOLYGON") |
| 60 | + ))) { |
| 61 | + stop(sprintf( |
| 62 | + "'%s' must be an sf object with geometry type 'POLYGON' or 'MULTIPOLYGON'.", |
| 63 | + deparse(substitute(polygon)) |
| 64 | + )) |
| 65 | + } |
64 | 66 | } |
65 | 67 | } |
66 | 68 |
|
|
140 | 142 | } |
141 | 143 | } |
142 | 144 |
|
| 145 | +.check_optimize <- function(optimize) { |
| 146 | + optimizations <- c("balanced", "quality", "performance") |
| 147 | + if (!optimize %in% optimizations) { |
| 148 | + stop( |
| 149 | + sprintf( |
| 150 | + "Optimization method '%s' not valid, must be in ('%s').", |
| 151 | + optimize, |
| 152 | + paste(optimizations, collapse = "', '") |
| 153 | + ) |
| 154 | + ) |
| 155 | + } |
| 156 | +} |
| 157 | + |
143 | 158 | .check_range_type <- function(range_type) { |
144 | 159 | range_types <- c("distance", "time", "consumption") |
145 | 160 | if (!range_type %in% range_types) { |
|
198 | 213 | )) |
199 | 214 | } |
200 | 215 | } |
| 216 | + |
| 217 | +.check_internet <- function() { |
| 218 | + access <- tryCatch( |
| 219 | + { |
| 220 | + curl::has_internet() |
| 221 | + }, |
| 222 | + error = function(cond) { |
| 223 | + warning(cond) |
| 224 | + return(FALSE) |
| 225 | + } |
| 226 | + ) |
| 227 | + if (!access) { |
| 228 | + stop("Connection error: Please check internet access and proxy configuration.") |
| 229 | + } |
| 230 | +} |
0 commit comments