Skip to content

Commit

Permalink
Use chunk label for variable name of modelfit object returned by eng_…
Browse files Browse the repository at this point in the history
…stan

Incidentally fixes the R CMD check error:
```
eng_stan: no visible binding for global variable ‘model_name’
```
  • Loading branch information
jrnold committed Dec 1, 2014
1 parent 6b1e4ea commit d4f3749
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,16 @@ eng_Rcpp = function(options) {

## Stan
## Compiles Stan model in the chunk, creates a stanmodel object,
## and assigns it to engine.opts$x.
## and assigns it to a variable with the name of the chunk label
eng_stan = function(options) {
code = paste(options$code, collapse = '\n')
opts = options$engine.opts
if (!is.environment(opts$env)) env = knit_global()
else env = opts$env
opts$env = NULL
#' name of the modelfit object returned by stan_model
if (is.null(opts$x))
if (!is.null(opts$model_name)) x = model_name
else x = formals(getFromNamespace('stan_model', 'rstan'))$model_name
else x = as.character(opts$x)
opts$x = NULL
x = make.names(options$label)
if (options$eval) {
message(sprintf('Creating the \'rstan::stanmodel\' object \'%s\' from Stan code', x))
message(sprintf('Creating the \'rstan::stanmodel\' object \'%s\' from code chunk.', x))
assign(x,
do.call(getFromNamespace('stan_model', 'rstan'),
c(list(model_code = code), opts)),
Expand Down

0 comments on commit d4f3749

Please sign in to comment.