Skip to content

Commit

Permalink
expose_stan_functions.R: hacks to get new version working
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodri committed Sep 10, 2017
1 parent 57068b6 commit b4ae642
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rstan/rstan/R/expose_stan_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,19 @@ expose_stan_functions <- function(stanmodel, ...) {
return(invisible(compiled$functions))
}

# This does not work yet
expose_stan_functions <- function(file, ...) {
model_code <- get_model_strcode(file, NULL)
model_cppname <- legitimate_model_name(basename(file), obfuscate_name = TRUE)
r <- .Call("stanfuncs", model_code, model_cppname, allow_undefined = FALSE)
code <- sub("_header.hpp>\n", "_header.hpp>\n#include <stan/model/model_header.hpp>",
r$cppcode, fixed = TRUE)
code <- sub("// [[Rcpp::export]]", "", code, fixed = TRUE)
code <- sub("// [[Rcpp::depends(rstan)]]",
"// [[Rcpp::depends(rstan)]]\n#include <Rcpp.h>\n#include <RcppEigen.h>",
code, fixed = TRUE)
code <- gsub("pstream__);", "&Rcpp::Rcout);", code, fixed = TRUE)
code <- gsub(", std::ostream* pstream__ = 0){", "){", code, fixed = TRUE)
code <- gsub("(std::ostream* pstream__ = 0){", "(){", code, fixed = TRUE)
compiled <- Rcpp::sourceCpp(code = paste(code, collapse = "\n"), ...)
return(invisible(compiled$functions))
}

0 comments on commit b4ae642

Please sign in to comment.