Skip to content

Commit

Permalink
Make sure obj_file location not null
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jan 11, 2024
1 parent cc9cde2 commit 284b6d5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
3 changes: 1 addition & 2 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ init_model_methods <- function(seed = 0, verbose = FALSE, hessian = FALSE, force
require_suggested_package("Rcpp")
require_suggested_package("RcppEigen")
if (length(private$model_methods_env_$hpp_code_) == 0 &&
(is.null(private$model_methods_env_$obj_file_) ||
!file.exists(private$model_methods_env_$obj_file_))) {
!file.exists(private$model_methods_env_$obj_file_)) {
stop("Model methods cannot be used with a pre-compiled Stan executable, ",
"the model must be compiled again", call. = FALSE)
}
Expand Down
5 changes: 1 addition & 4 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,7 @@ compile <- function(quiet = TRUE,
file.remove(exe)
}
file.copy(tmp_exe, exe, overwrite = TRUE)
model_obj_file <- paste0(temp_file_no_ext, ".o")
if (file.exists(model_obj_file)) {
private$model_methods_env_$obj_file_ <- model_obj_file
}
private$model_methods_env_$obj_file_ <- paste0(temp_file_no_ext, ".o")
if (os_is_wsl()) {
res <- processx::run(
command = "wsl",
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ expose_model_methods <- function(env, force_recompile = FALSE, verbose = FALSE)
file.copy(model_methods_cpp, source_file, overwrite = FALSE)

model_obj_file <- env$obj_file_
if (is.null(model_obj_file) || !file.exists(model_obj_file)) {
if (!file.exists(model_obj_file)) {
if (rlang::is_interactive()) {
message("Model object file not found, recompiling model...")
}
Expand Down

0 comments on commit 284b6d5

Please sign in to comment.