Skip to content

Commit

Permalink
add initial restructure() function
Browse files Browse the repository at this point in the history
  • Loading branch information
venpopov committed Mar 6, 2024
1 parent 00db81b commit 9ff528f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: bmm
Title: Easy and Accesible Bayesian Measurement Models using 'brms'
Version: 0.4.2.9000
Version: 0.4.3.9000
Authors@R: c(
person("Vencislav", "Popov", , "[email protected]", role = c("aut", "cre", "cph")),
person("Gidon", "Frischkorn", , "[email protected]", role = c("aut", "cph")),
Expand Down Expand Up @@ -42,7 +42,8 @@ Imports:
stats,
matrixStats,
crayon,
methods
methods,
assertthat
URL: https://github.com/venpopov/bmm, https://venpopov.github.io/bmm/
BugReports: https://github.com/venpopov/bmm/issues
Additional_repositories:
Expand Down
37 changes: 37 additions & 0 deletions R/restructure.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
restructure.bmm <- function(x) {
assert_that(is_bmmfit(x), msg = "Please provide a bmmfit object")
version <- x$version$bmm
if (is.null(version)) {
version <- as.package_version('0.1.1')
}
current_version <- utils::packageVersion('bmm')
restr_version <- restructure_version.bmm(x)

if (restr_version >= current_version) {
return(x)
}

if (restr_version < "0.4.3") {
x <- add_links(x)
}

x$version$bmm_restructure <- current_version
brms::restructure(x)
}

restructure_version.bmm <- function(x) {
out <- x$version$bmm_restructure
if (!is.package_version(out)) {
out <- x$version$bmm
}
out
}

add_links <- function(x) {
model_name <- class(x$bmm$model)[length(class(x$bmm$model))]
new_model <- get_model(model_name)()
x$bmm$model$info$links <- new_model$info$links
x
}


0 comments on commit 9ff528f

Please sign in to comment.