R/stanmodels.R

# Generated by rstantools.  Do not edit by hand.

# names of stan models
stanmodels <- c("bi_ind", "bi_left", "bi_mirror", "bi_none", "bi_right", "multi_ind", "multi_left", "multi_mirror", "multi_none", "multi_right", "pheno_constant", "pheno_independent", "pheno_pooled")

# load each stan module
Rcpp::loadModule("stan_fit4bi_ind_mod", what = TRUE)
Rcpp::loadModule("stan_fit4bi_left_mod", what = TRUE)
Rcpp::loadModule("stan_fit4bi_mirror_mod", what = TRUE)
Rcpp::loadModule("stan_fit4bi_none_mod", what = TRUE)
Rcpp::loadModule("stan_fit4bi_right_mod", what = TRUE)
Rcpp::loadModule("stan_fit4multi_ind_mod", what = TRUE)
Rcpp::loadModule("stan_fit4multi_left_mod", what = TRUE)
Rcpp::loadModule("stan_fit4multi_mirror_mod", what = TRUE)
Rcpp::loadModule("stan_fit4multi_none_mod", what = TRUE)
Rcpp::loadModule("stan_fit4multi_right_mod", what = TRUE)
Rcpp::loadModule("stan_fit4pheno_constant_mod", what = TRUE)
Rcpp::loadModule("stan_fit4pheno_independent_mod", what = TRUE)
Rcpp::loadModule("stan_fit4pheno_pooled_mod", what = TRUE)

# instantiate each stanmodel object
stanmodels <- 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("model_", model_name)))
})
tjthurman/BAHZ documentation built on May 30, 2020, 8:28 a.m.