Skip to content

Commit 15d8445

Browse files
committed
Test for Inf in covariate columns #408
1 parent 5bda313 commit 15d8445

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-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.9028
4+
Version: 0.6.0.9029
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 check for `Inf`/`-Inf` values before fitting. #408
4+
35
* Add priors for `breakpt()` and `logistic()` parameters. #403
46

57
* Add linear component of smoothers to `tidy()`. #90

R/fit.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,12 @@ sdmTMB <- function(
859859
formula_no_bars_no_sm <- remove_s_and_t2(formula_no_bars)
860860
X_ij[[ii]] <- model.matrix(formula_no_bars_no_sm, data)
861861
mf[[ii]] <- model.frame(formula_no_bars_no_sm, data)
862+
vars <- colnames(mf[[ii]])
863+
for (g in seq_along(vars)) {
864+
if (any(is.infinite(mf[[ii]][, g, drop = TRUE]))) {
865+
cli_abort("Column `{vars[g]}` had an Inf/-Inf value. Please remove this before fitting the model.")
866+
}
867+
}
862868

863869
mt[[ii]] <- attr(mf[[ii]], "terms")
864870
# parse everything mgcv + smoothers:

tests/testthat/test-index.R

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,17 @@ test_that("get_index works", {
187187
#
188188
# })
189189

190+
# https://github.com/pbs-assess/sdmTMB/issues/408
191+
test_that("Models error our nicely with Inf or -Inf covariates before get_index()", {
192+
d <- pcod
193+
d$depth_scaled[1] <- -Inf
194+
expect_error(m <- sdmTMB(
195+
data = d,
196+
formula = density ~ 0 + as.factor(year) + depth_scaled,
197+
spatiotemporal = "off", # speed
198+
spatial = "off", # speed
199+
time = "year",
200+
family = delta_gamma(type = "poisson-link")
201+
), regexp = "Inf")
202+
})
203+

0 commit comments

Comments
 (0)