Skip to content

Commit b79b992

Browse files
Copilotosorensen
andcommitted
Add input validation to print method
Co-authored-by: osorensen <21175639+osorensen@users.noreply.github.com>
1 parent 37ff404 commit b79b992

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

R/print.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
#' mod
4040
#'
4141
print.BayesMallowsSMC2 <- function(x, ...) {
42+
# Basic validation
43+
if (!inherits(x, "BayesMallowsSMC2")) {
44+
stop("x must be an object of class 'BayesMallowsSMC2'")
45+
}
46+
47+
required_fields <- c("alpha", "rho", "ESS", "resampling", "log_marginal_likelihood")
48+
missing_fields <- setdiff(required_fields, names(x))
49+
if (length(missing_fields) > 0) {
50+
stop("Object is missing required fields: ", paste(missing_fields, collapse = ", "))
51+
}
52+
4253
# Extract dimensions
4354
n_particles <- ncol(x$alpha)
4455
n_timepoints <- length(x$ESS)

0 commit comments

Comments
 (0)