Skip to content

Commit

Permalink
Merge branch 'master' into use-params-for-doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Dec 17, 2020
2 parents 8810cd7 + dcdffb7 commit 2259468
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ eng_cmdstan <- function(options) {
}
file <- write_stan_file(options$code, dir = dir)
mod <- cmdstan_model(file)
assign(output_var, mod, envir = knitr::knit_global())
assign(output_var, mod, envir = cmdstanr_knitr_env())
}
options$engine <- "stan" # for syntax highlighting
code <- paste(options$code, collapse = "\n")
Expand Down
29 changes: 20 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
.onAttach <- function(...) {
startup_messages()
}

.onLoad <- function(...) {
cmdstanr_initialize()
}


startup_messages <- function() {
packageStartupMessage("This is cmdstanr version ", utils::packageVersion("cmdstanr"))
packageStartupMessage("- Online documentation and vignettes at mc-stan.org/cmdstanr")
Expand Down Expand Up @@ -65,3 +56,23 @@ cmdstanr_initialize <- function() {
}
invisible(TRUE)
}

cmdstanr_knitr_env_function_generator <- function(env1) {
function(env2 = NULL) {
if (!is.null(env2)) {
env1 <<- env2
}
invisible(env1)
}
}
cmdstanr_knitr_env <- cmdstanr_knitr_env_function_generator(new.env())


.onAttach <- function(...) {
startup_messages()
}

.onLoad <- function(...) {
cmdstanr_knitr_env(knitr::knit_global())
cmdstanr_initialize()
}

0 comments on commit 2259468

Please sign in to comment.