Skip to content

Commit f0116fe

Browse files
committed
throw error instead
1 parent fd475d7 commit f0116fe

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

R/fortify-map.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ map_data <- function(map, region = ".", exact = FALSE, ...) {
8888
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
8989

9090
if (!inherits(map_obj, "map")) {
91-
return(fortify(map_obj))
91+
cli::cli_abort(c(
92+
"{.fn maps::map} must return an object of type {.cls map}, not \\
93+
{obj_type_friendly(map_obj)}.",
94+
i = "Did you pass the right arguments?"
95+
))
9296
}
9397

9498
df <- data_frame0(

tests/testthat/_snaps/geom-map.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@
66

77
`map` must have the columns `x`, `y`, and `id`.
88

9+
# map_data() checks it input
10+
11+
Code
12+
map_data("world", namesonly = TRUE)
13+
Condition
14+
Error in `map_data()`:
15+
! `maps::map()` must return an object of type <map>, not a character vector.
16+
i Did you pass the right arguments?
17+

tests/testthat/test-geom-map.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ test_that("geom_map() checks its input", {
22
expect_snapshot_error(geom_map(map = letters))
33
expect_snapshot_error(geom_map(map = mtcars))
44
})
5+
6+
test_that("map_data() checks it input", {
7+
skip_if_not_installed("maps")
8+
expect_snapshot(map_data("world", namesonly = TRUE), error = TRUE)
9+
})

0 commit comments

Comments
 (0)