Skip to content

Commit

Permalink
remove duplication in precompile_bmcm_model
Browse files Browse the repository at this point in the history
  • Loading branch information
n8thangreen committed Aug 12, 2024
1 parent caf1940 commit 9e7d740
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
7 changes: 5 additions & 2 deletions R/bmcm_stan.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ compile_model <- function(use_cmdstanr, model_code, model_name) {
model_path <-
cmdstanr::write_stan_file(
model_code, dir = ".", basename = model_name)
return(cmdstanr::cmdstan_model(stan_file = model_path))
return(cmdstanr::cmdstan_model(stan_file = model_path, compile = TRUE))
} else {
return(rstan::stan_model(model_code = model_code, model_name = model_name))
out <- rstan::stan_model(model_code = model_code, model_name = model_name)
saveRDS(precompiled_model, file = glue::glue("{model_name}.RDS"))

return(out)
}
}

Expand Down
11 changes: 2 additions & 9 deletions R/precompile_bmcm_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ precompile_bmcm_model <- function(input_data,
paste0("bmcm_stan_", glue::glue_collapse(distns, sep = "_"))
}

if (use_cmdstanr) {
model_path <- cmdstanr::write_stan_file(model_code, dir = ".", basename = model_name)
precompiled_model <- cmdstanr::cmdstan_model(stan_file = model_path, compile = TRUE)
} else {
precompiled_model <- rstan::stan_model(model_code = model_code,
model_name = model_name)
saveRDS(precompiled_model, file = glue::glue("{model_name}.RDS"))
}
out <- compile_model(use_cmdstanr, model_code, model_name)

invisible(precompiled_model)
invisible(out)
}

0 comments on commit 9e7d740

Please sign in to comment.