Skip to content

Commit

Permalink
allow users to pass a custom environment to Rcpp::sourceCpp(); fixes h…
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Feb 15, 2013
1 parent 1f18ebb commit b600f7f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

- the function `imgur_upload()` uses Imgur API version 3 now; if you are using the key obtained from version 2, you need to register for your own client id: http://api.imgur.com (#439)

- allow users to pass a custom environment to `Rcpp::sourceCpp()` in the `Rcpp` engine; fixes http://stackoverflow.com/q/14882486/559676

- slight improvement of encoding support in `knit()`

# CHANGES IN knitr VERSION 1.0
Expand Down
7 changes: 3 additions & 4 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ eng_Rcpp = function(options) {
code = str_c(options$code, collapse = '\n')
# engine.opts is a list of arguments to be passed to Rcpp function, e.g.
# engine.opts=list(plugin='RcppArmadillo')
opts = options$engine.opts
if (!is.environment(opts$env)) opts$env = knit_global() # default env is knit_global()
if (options$eval) {
message('Building shared library for Rcpp code chunk...')
do.call(
Rcpp::sourceCpp,
c(list(code = code, env = knit_global()), options$engine.opts)
)
do.call(Rcpp::sourceCpp, c(list(code = code), opts))
}

options$engine = 'cpp' # wrap up source code in cpp syntax instead of Rcpp
Expand Down

0 comments on commit b600f7f

Please sign in to comment.