Skip to content

Commit

Permalink
Merge pull request #299 from pbs-assess/ericward-noaa-patch-2
Browse files Browse the repository at this point in the history
Add new message about time
  • Loading branch information
seananderson authored Feb 14, 2024
2 parents 74c0d58 + 8af5427 commit 1f57409
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ sdmTMB <- function(
if (!is.null(time)) {
assert_that(time %in% names(data),
msg = "Specified `time` column is missing from `data`.")
assert_that(sum(is.na(as.numeric(data[[time]]))) == 0L,
msg = "Specified `time` column can't be coerced to a numeric value or contains NAs. Please remove any NAs in the time column.")
}
if (is.null(time)) {
time <- "_sdmTMB_time"
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-2-fit-less-basic.R
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,15 @@ test_that("sdmTMB throws error on AR1/RW with non-numeric time", {
mesh = pcod_mesh_2011
))
})

test_that("Time with an NA gets flagged", {
skip_on_cran()
d <- pcod_2011
d$yr <- as.character(d$year)
d$yr[2] <- NA
expect_error({
m <- sdmTMB(density ~ 1, time = "yr", spatial = "off", spatiotemporal = "off", data = d)
}, regexp = "time")
})


0 comments on commit 1f57409

Please sign in to comment.