Permalink
Browse files

allow users to pass a custom environment to Rcpp::sourceCpp(); fixes h…

  • Loading branch information...
1 parent 1f18ebb commit b600f7fe8cfd265726f3d9e8ae0c2c1c361ce162 @yihui committed Feb 15, 2013
Showing with 5 additions and 4 deletions.
  1. +2 −0 NEWS.md
  2. +3 −4 R/engine.R
View
2 NEWS.md
@@ -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
View
7 R/engine.R
@@ -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

0 comments on commit b600f7f

Please sign in to comment.