From 35ece2f09c38eace7ba1c121535445d4c0dae600 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Thu, 21 Mar 2024 13:37:35 -0700 Subject: [PATCH] Improve update_version checks [skip ci] --- R/utils.R | 12 ++++++------ scratch/test-versions.R | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index e6e7734f1..da225a9a3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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 @@ -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 @@ -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 } diff --git a/scratch/test-versions.R b/scratch/test-versions.R index f0def8e17..40394f33f 100644 --- a/scratch/test-versions.R +++ b/scratch/test-versions.R @@ -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)