diff --git a/NAMESPACE b/NAMESPACE index 807ff49..9cd12f4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,6 @@ importFrom("RcppParallel", "CxxFlags", "RcppParallelLibs") import(rstantools) -export("bsam") +export("bsam", "bsam_model") useDynLib(bsam, .registration = TRUE) diff --git a/R/stanmodels.R b/R/stanmodels.R new file mode 100644 index 0000000..3ff28e5 --- /dev/null +++ b/R/stanmodels.R @@ -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))) +})