Skip to content

Commit 796eb08

Browse files
committed
Add progress bar in simulate.sdmTMB() #346
Also silent = FALSE by default
1 parent 11506d9 commit 796eb08

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
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.9008
4+
Version: 0.6.0.9009
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 progress bar to `simulate.sdmTMB()`. #346
4+
35
* Add AUC and TSS examples to cross validation vignette. #268
46

57
* Add `model` (linear predictor number) argument to coef() method. Also,

R/tmb-sim.R

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ sdmTMB_simulate <- function(formula,
381381
simulate.sdmTMB <- function(object, nsim = 1L, seed = sample.int(1e6, 1L),
382382
type = c("mle-eb", "mle-mvn"),
383383
model = c(NA, 1, 2),
384-
re_form = NULL, mcmc_samples = NULL, silent = TRUE, ...) {
384+
re_form = NULL, mcmc_samples = NULL, silent = FALSE, ...) {
385385
set.seed(seed)
386386
type <- tolower(type)
387387
type <- match.arg(type)
@@ -421,18 +421,21 @@ simulate.sdmTMB <- function(object, nsim = 1L, seed = sample.int(1e6, 1L),
421421
new_par <- mcmc_samples
422422
}
423423

424-
# do the sim
424+
# do the simulation
425+
if (!silent) cli::cli_progress_bar("Simulating...", total = nsim)
426+
ret <- list()
425427
if (!is.null(mcmc_samples)) { # we have a matrix
426-
ret <- lapply(seq_len(nsim), function(i) {
427-
if (!silent) cat("-")
428-
newobj$simulate(par = new_par[, i, drop = TRUE], complete = FALSE)$y_i
429-
})
428+
for (i in seq_len(nsim)) {
429+
if (!silent) cli::cli_progress_update()
430+
ret[[i]] <- newobj$simulate(par = new_par[, i, drop = TRUE], complete = FALSE)$y_i
431+
}
430432
} else {
431-
ret <- lapply(seq_len(nsim), function(i) {
432-
if (!silent) cat("-")
433-
newobj$simulate(par = new_par, complete = FALSE)$y_i
434-
})
433+
for (i in seq_len(nsim)) {
434+
if (!silent) cli::cli_progress_update()
435+
ret[[i]] <- newobj$simulate(par = new_par, complete = FALSE)$y_i
436+
}
435437
}
438+
cli::cli_progress_done()
436439

437440
if (isTRUE(object$family$delta)) {
438441
if (is.na(model[[1]])) {

man/simulate.sdmTMB.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)