Skip to content

Commit

Permalink
Improve update_version checks [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
seananderson committed Mar 21, 2024
1 parent 9f0ac47 commit 35ece2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ get_fitted_time <- function(x) {
}

update_version <- function(object) {
if (object$version < '0.4.3') {
if (object$version < "0.4.3") {
cli::cli_abort("`update_version()` only works with models fit with version 0.4.3 or later.")
}
if (!"fitted_time" %in% names(object)) { # < 0.4.3.9004
Expand All @@ -606,13 +606,13 @@ update_version <- function(object) {
object$offset <- o

y <- object$response
y <- y[seq(1, real_data_n),,drop=FALSE]
y <- y[seq(1, real_data_n), , drop = FALSE]
object$response <- y

d <- object$data
d[['__fake_data__']] <- d[['__weight_sdmTMB__']] <-
d[['__sdmTMB_offset__']] <- d[['__dcens_upr__']] <- NULL
d <- d[seq(1, real_data_n),,drop=FALSE]
d[["__fake_data__"]] <- d[["__weight_sdmTMB__"]] <-
d[["__sdmTMB_offset__"]] <- d[["__dcens_upr__"]] <- NULL
d <- d[seq(1, real_data_n), , drop = FALSE]
object$data <- d

# add gengamma_Q
Expand All @@ -634,6 +634,6 @@ update_version <- function(object) {
object$tmb_obj$env$last.par.best <- ee$last.par.best
object$tmb_map <- map
}
object
}
object
}
19 changes: 19 additions & 0 deletions scratch/test-versions.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ check_version(f)

f <- "scratch/version-checks/fit-0.4.3.9003.rds"
check_version(f)

## current
mesh <- make_mesh(pcod, c("X", "Y"), cutoff = 15)
pcod$os <- rep(log(0.01), nrow(pcod)) # offset
f <- "scratch/version-checks/fit-main.rds"
fit <- sdmTMB(
data = pcod,
formula = density ~ s(depth_scaled, k = 3),
mesh = mesh,
offset = pcod$os,
family = tweedie(link = "log"),
time = "year",
time_varying = ~ 1,
time_varying_type = 'ar1',
extra_time = c(2006, 2008, 2010, 2012, 2014, 2016),
spatiotemporal = "off"
)
saveRDS(fit, f)
check_version(f)

0 comments on commit 35ece2f

Please sign in to comment.