Skip to content

Commit

Permalink
export stan model
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmerkle committed May 7, 2024
1 parent 369e339 commit 7651a9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ importFrom("RcppParallel", "CxxFlags", "RcppParallelLibs")

import(rstantools)

export("bsam")
export("bsam", "bsam_model")

useDynLib(bsam, .registration = TRUE)
25 changes: 25 additions & 0 deletions R/stanmodels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by rstantools. Do not edit by hand.

# names of stan models
stanmodels <- c("stanmarg_bsam")

# load each stan module
Rcpp::loadModule("stan_fit4stanmarg_bsam_mod", what = TRUE)

# instantiate each stanmodel object
bsam_model <- sapply(stanmodels, function(model_name) {
# create C++ code for stan model
stan_file <- if(dir.exists("stan")) "stan" else file.path("inst", "stan")
stan_file <- file.path(stan_file, paste0(model_name, ".stan"))
stanfit <- rstan::stanc_builder(stan_file,
allow_undefined = TRUE,
obfuscate_model_name = FALSE)
stanfit$model_cpp <- list(model_cppname = stanfit$model_name,
model_cppcode = stanfit$cppcode)
# create stanmodel object
methods::new(Class = "stanmodel",
model_name = stanfit$model_name,
model_code = stanfit$model_code,
model_cpp = stanfit$model_cpp,
mk_cppmodule = function(x) get(paste0("rstantools_model_", model_name)))
})

0 comments on commit 7651a9c

Please sign in to comment.