Skip to content

Commit

Permalink
Enforce xrange, yrange as two-dimensional vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
bodkan committed Mar 28, 2022
1 parent e7fe742 commit df95369
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ time (gene flow %s -> %s in the time window %s-%s)",
#' @example man/examples/spatial_functions.R
world <- function(xrange, yrange, landscape = "naturalearth", crs = NULL,
scale = c("small", "medium", "large")) {
if (length(xrange) != 2 || length(yrange) != 2)
stop("Horizontal (i.e. longitude) and vertical (i.e. latitude) must be\n",
"specified as two-dimensional vectors such as:\n",
" `xrange = c(x1, x2), yrange = c(y1, y2)`",
call. = FALSE)

if (inherits(landscape, "sf")) { # a landscape defined by the user
cropped_landscape <- sf::st_crop(
landscape,
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-naturalearth.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ test_that("all three variants of the Natural Earth data can be downloaded", {
expect_s3_class(medium, "slendr_map")
expect_s3_class(large, "slendr_map")
})

test_that("world dimensions are correctly specified", {
expect_error(world(1:100, 1:100, landscape = "blank"))
expect_s3_class(world(c(1, 100), c(1, 100), landscape = "blank"), "slendr_map")
})

0 comments on commit df95369

Please sign in to comment.