Skip to content

implement s7 classes#87

Merged
MaartenMarsman merged 1 commit intoBayesian-Graphical-Modelling-Lab:mainfrom
vandenman:feature/s7
Mar 27, 2026
Merged

implement s7 classes#87
MaartenMarsman merged 1 commit intoBayesian-Graphical-Modelling-Lab:mainfrom
vandenman:feature/s7

Conversation

@vandenman
Copy link
Copy Markdown
Collaborator

Fixes https://github.com/Bayesian-Graphical-Modelling-Lab/issues/issues/79

Description

Provide a concise summary of the changes.

Problem / Motivation

This fixes the fragile S3 methods with cache for lazy computations, those are now implemented like so:

bgms_class = new_class("bgms",
  package = NULL,
  properties = list(
    # --- Core (always present) ---
    arguments = new_property(class_any),
    raw_samples = new_property(class_any),
    cache = new_property(class_any),

    # --- Posterior means (set during construction, immutable) ---
    posterior_mean_main = new_property(class_any, default = NULL),

# < omitted stuff >

    # --- Lazy MCMC diagnostics (computed on first access via getter) ---
    posterior_summary_main = new_property(
      class = class_any,
      getter = function(self) {
        ensure_summaries(self)
        self@cache[["posterior_summary_main"]]
      }
    ),

# < omitted stuff >

)

So there is a proper getter method that does the computation.

Note that we have a lot of class_any. This could be a more constrained type, but for now this is fine I think.

Key difference for users

# Old behaviour
data("Wenchuan")
fit <- bgm(Wenchuan)
class(fit) # "bgms"
fit$posterior_mean_main # <- uses '$'
# New behaviour
data("Wenchuan")
fit <- bgm(Wenchuan)
class(fit) # "bgms"      "S7_object"
fit@posterior_mean_main # <- uses '@'

However, if users do/ did extract_main_effects then nothing changed.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Performance optimization
  • Statistical / methodological update

Documentation and Release Notes

  • Updated function documentation for any signature or behaviour changes
  • Regenerated man/*.Rd files if roxygen comments changed
  • Updated _pkgdown.yml if adding a new exported function
  • Added or updated NEWS.md entry if the change affects users

Testing and Validation

Describe the checks you ran and the main results.

  • Added or updated tests in tests/testthat/ when needed
  • Ran the project styler
source("inst/styler/bgms_style.R")
styler::style_pkg(style = bgms_style)
  • Checked test files for styled result = captures that must be reverted to result <-
  • Ran lintr::lint_package()
  • Ran roxygen2::roxygenise() if roxygen comments changed
  • Ran rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran")) for non-trivial changes
  • Verified numerical behaviour where relevant

@vandenman
Copy link
Copy Markdown
Collaborator Author

The R devel check fails because some other R package could not be installed.

@MaartenMarsman MaartenMarsman merged commit 822a280 into Bayesian-Graphical-Modelling-Lab:main Mar 27, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants