Skip to content

Commit

Permalink
Merge pull request #229 from mrc-ide/gh-226
Browse files Browse the repository at this point in the history
Implement str for pmcmc_samples objects
  • Loading branch information
r-ash committed Jul 11, 2023
2 parents d880897 + 7832a7c commit df7d24f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/make-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-pandoc@v1

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-pandoc@v1

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mcstate
Title: Monte Carlo Methods for State Space Models
Version: 0.9.15
Version: 0.9.16
Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"),
email = "rich.fitzjohn@gmail.com"),
person("Marc", "Baguelin", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method(format,mcstate_pmcmc)
S3method(predict,mcstate_pmcmc)
S3method(predict,smc2_result)
S3method(print,mcstate_pmcmc)
S3method(str,mcstate_pmcmc)
export(adaptive_proposal_control)
export(array_bind)
export(array_drop)
Expand Down
7 changes: 7 additions & 0 deletions R/pmcmc_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ print.mcstate_pmcmc <- function(x, ...) {
}


##' @export
str.mcstate_pmcmc <- function(object, ...) {
object <- unclass(object)
NextMethod("str")
}


## NOTE: we need to expose a 'force' argument here for testing, as
## otherwise under R CMD check the progress bar does not run.
pmcmc_progress <- function(n_steps, progress, simple = FALSE, force = FALSE) {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-pmcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,14 @@ test_that("can run pmcmc for ode models", {
expect_equal(results1$predict$model_time, results1$predict$time)
expect_identical(results1$predict$filter, p1$inputs())
})


test_that("can use str() without error on samples object", {
dat <- example_uniform()
control <- pmcmc_control(10, save_state = FALSE, save_trajectories = FALSE)
res <- pmcmc(dat$pars, dat$filter, control = control)
cmp <- structure(res, class = NULL)
expect_output(str(res),
paste(capture.output(str(cmp)), collapse = "\n"),
fixed = TRUE)
})

0 comments on commit df7d24f

Please sign in to comment.