Skip to content

Commit

Permalink
Merge pull request #1615 from venpopov/restructure-s3
Browse files Browse the repository at this point in the history
make restructure an S3 method
  • Loading branch information
paul-buerkner authored Mar 8, 2024
2 parents 5e86c9c + d140d66 commit b9d23f7
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 23 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ S3method(rescale_old_mo,btl)
S3method(rescale_old_mo,btnl)
S3method(rescale_old_mo,mvbrmsterms)
S3method(residuals,brmsfit)
S3method(restructure,brmsfit)
S3method(rhat,brmsfit)
S3method(stan_log_lik,brmsterms)
S3method(stan_log_lik,family)
Expand Down
2 changes: 1 addition & 1 deletion R/priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ prior_string <- function(prior, ...) {
#' Default priors for Bayesian models
#'
#' @description \code{default_prior} is a generic function that can be used to
#' get default priors for Bayesian models. It's original use is
#' get default priors for Bayesian models. Its original use is
#' within the \pkg{brms} package, but new methods for use
#' with objects from other packages can be registered to the same generic.
#'
Expand Down
30 changes: 28 additions & 2 deletions R/restructure.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
#' Restructure Old R Objects
#'
#' \code{restructure} is a generic function used to restructure old R objects to
#' work with newer versions of the package that generated them. Its original
#' use is within the \pkg{brms} package, but new methods for use with objects
#' from other packages can be registered to the same generic.
#'
#' @param x An object to be restructured. The object's class will determine
#' which method to apply
#' @param ... Additional arguments to pass to the specific methods
#'
#' @details Usually the version of the package that generated the object will be
#' stored somewhere in the object and this information will be used by the
#' specific method to determine what transformations to apply. See
#' \code{\link[brms:restructure.brmsfit]{restructure.brmsfit}} for the default
#' method applied for \pkg{brms} models. You can view the available methods by
#' typing: \code{methods(restructure)}
#'
#' @return An object of the same class as \code{x} compatible with the latest
#' version of the package that generated it.
#'
#' @seealso \code{\link{restructure.brmsfit}}
#' @export
restructure <- function(x, ...) {
UseMethod("restructure")
}

#' Restructure Old \code{brmsfit} Objects
#'
#' Restructure old \code{brmsfit} objects to work with
Expand All @@ -20,8 +47,7 @@
#' of \pkg{brms}.
#'
#' @export
restructure <- function(x, ...) {
stopifnot(is.brmsfit(x))
restructure.brmsfit <- function(x, ...) {
if (is.null(x$version)) {
# this is the latest version without saving the version number
x$version <- list(brms = package_version("0.9.1"))
Expand Down
2 changes: 1 addition & 1 deletion R/stancode.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title Stan Code for Bayesian models
#'
#' @description \code{stancode} is a generic function that can be used to
#' generate Stan code for Bayesian models. It's original use is
#' generate Stan code for Bayesian models. Its original use is
#' within the \pkg{brms} package, but new methods for use
#' with objects from other packages can be registered to the same generic.
#'
Expand Down
2 changes: 1 addition & 1 deletion R/standata.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title Stan data for Bayesian models
#'
#' @description \code{standata} is a generic function that can be used to
#' generate data for Bayesian models to be passed to Stan. It's original use is
#' generate data for Bayesian models to be passed to Stan. Its original use is
#' within the \pkg{brms} package, but new methods for use
#' with objects from other packages can be registered to the same generic.
#'
Expand Down
2 changes: 1 addition & 1 deletion man/default_prior.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions man/restructure.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/restructure.brmsfit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/stancode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/standata.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b9d23f7

Please sign in to comment.