Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

align file_refit options with brms #234

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if these changes are correct! I was a little confused because previously the documentation states that file_refit = TRUE would lead to re-using a saved model, and file_refit = FALSE would refit the model. I would have expected to be exactly the other way around, and I think this is also what is implemented in the read_bmmfit function.

#' 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.