Skip to content

Commit 870ad8c

Browse files
committed
Add error msg if coord NAs in make_mesh #365
1 parent 1be189e commit 870ad8c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: sdmTMB
33
Title: Spatial and Spatiotemporal SPDE-Based GLMMs with 'TMB'
4-
Version: 0.6.0.9006
4+
Version: 0.6.0.9007
55
Authors@R: c(
66
person(c("Sean", "C."), "Anderson", , "sean@seananderson.ca",
77
role = c("aut", "cre"),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sdmTMB (development version)
22

3+
* Add helpful error message if some coordinates in make_mesh() are NA. #365
4+
35
* Add informative message if fitting with an offset but predicting with offset
46
argument left at NULL on newdata. #372
57

R/mesh.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ make_mesh <- function(data, xy_cols,
8888
cli_abort(msg)
8989
}
9090

91+
all_x_non_na <- sum(is.na(data[[xy_cols[[1]]]])) == 0L
92+
all_y_non_na <- sum(is.na(data[[xy_cols[[2]]]])) == 0L
93+
if (!all_x_non_na || !all_y_non_na) {
94+
msg <- c("Some coordinates in `xy_cols` were NA.", "
95+
Remove or fix these rows before proceeding.")
96+
cli_abort(msg)
97+
}
98+
9199
if (max(data[[xy_cols[1]]]) > 1e4 || max(data[[xy_cols[2]]] > 1e4)) {
92100
msg <- paste0(
93101
"The x or y column values are fairly large. ",

tests/testthat/test-mesh.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_that("make_mesh returns informative error if some coordinates are NA", {
2+
d <- data.frame(x = c(NA, runif(10)), y = c(NA, runif(10)))
3+
expect_error({make_mesh(d, xy_cols = c("x", "y"), cutoff = 1)}, regexp = "NA")
4+
5+
d <- data.frame(x = c(1, runif(10)), y = c(NA, runif(10)))
6+
expect_error({make_mesh(d, xy_cols = c("x", "y"), cutoff = 1)}, regexp = "NA")
7+
8+
d <- data.frame(x = c(NA, runif(10)), y = c(1, runif(10)))
9+
expect_error({make_mesh(d, xy_cols = c("x", "y"), cutoff = 1)}, regexp = "NA")
10+
11+
d <- data.frame(x = c(1, runif(10)), y = c(1, runif(10)))
12+
mesh <- make_mesh(d, xy_cols = c("x", "y"), cutoff = 1)
13+
})

0 commit comments

Comments
 (0)