Skip to content

Commit

Permalink
Merge pull request #234 from venpopov/align-file-refit-brms
Browse files Browse the repository at this point in the history
  • Loading branch information
venpopov authored Aug 23, 2024
2 parents 2a317f4 + 483a94a commit 46ac699
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features
* Updates to the `bmf2bf` S3 methods to more flexibly accommodate the translation of `bmmformulas` into `brmsformulas`
* the `file_refit` argument of the `bmm` function now accepts character string like brms. A warning is given when "on_change" is specified, as this is not currently implemented for `bmmodels`.

### Bug fixes
* Fix a conflict in setting default priors when model parameters were transformed in a non-linear formula
Expand Down
8 changes: 4 additions & 4 deletions R/bmm.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
#' @param file_compress Logical or a character string, specifying one of the
#' compression algorithms supported by [saveRDS] when saving
#' the fitted model object.
#' @param file_refit Logical. Modifies when the fit stored via the `file` argument is
#' @param file_refit Logical or character string. Modifies when the fit stored via the `file` argument is
#' re-used. Can be set globally for the current \R session via the
#' `"bmm.file_refit"` option (see [options]). If `TRUE` (the default), the
#' model is re-used if the file exists. If `FALSE`, the model is re-fitted. Note
#' that unlike `brms`, there is no "on_change" option
#' `"bmm.file_refit"` option (see [options]). If `TRUE` or "always", the
#' model is fitted again. If `FALSE` or "never" (the default), the model saved under the name specified in `file`
#' will be re-used. Note that unlike in `brms`, there is no "on_change" option
#' @param ... Further arguments passed to [brms::brm()] or Stan. See the
#' description of [brms::brm()] for more details
#'
Expand Down
13 changes: 13 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,19 @@ deprecated_args <- function(...) {

read_bmmfit <- function(file, file_refit) {
file <- check_rds_file(file)

if(is.character(file_refit)) {
stopif(!tolower(file_refit) %in% c("never", "always", "on_change"),
glue("You have provided an invalid option for the file_refit argument.\n",
"Valid options are: \"never\" or \"always\" \n",
"The \"on_change\" option available in brms is currently not implemented for bmm."))

warnif(tolower(file_refit) == "on_change",
glue("The \"on_change\" option for the file_refit argument available in brms,\n",
"is currently not implemented for bmm.\n",
"To avoid overwriting an already saved bmmfit object, file_refit was set to \"never\"."))
file_refit <- ifelse(file_refit == "always", TRUE, FALSE)
}
if (is.null(file) || file_refit) {
return(NULL)
}
Expand Down
8 changes: 4 additions & 4 deletions man/bmm.Rd

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

0 comments on commit 46ac699

Please sign in to comment.