R/save_load.R

Defines functions load_bnns save_bnns

Documented in load_bnns save_bnns

#' Save a fitted bnns model to disk
#'
#' @param object A fitted \code{bnns} object.
#' @param file A character string specifying the path where the model should be saved (usually ending in .rds).
#' @export
save_bnns <- function(object, file) {
  if (!inherits(object, "bnns")) {
    stop("Object must be of class 'bnns'.", call. = FALSE)
  }
  saveRDS(object, file)
  invisible(file)
}

#' Load a fitted bnns model from disk
#'
#' @param file A character string specifying the path to the saved model.
#' @return A fitted \code{bnns} object.
#' @export
load_bnns <- function(file) {
  object <- readRDS(file)
  if (!inherits(object, "bnns")) {
    stop("The file does not contain a valid 'bnns' object.", call. = FALSE)
  }
  return(object)
}

Try the bnns package in your browser

Any scripts or data that you put into this service are public.

bnns documentation built on June 8, 2026, 1:06 a.m.