Skip to content

Commit 2c0027d

Browse files
committed
Allow new_env() to create an environment with a specified parent
1 parent 8046a76 commit 2c0027d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ChangeLog

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2015-02-19 Lionel Henry <[email protected]>
2+
3+
* inst/include/Rcpp/Environment.h Allow new_env() to create an
4+
environment with a specified parent
5+
16
2015-02-19 JJ Allaire <[email protected]>
27

38
* vignettes/Rcpp-attributes.Rnw: Add note on using inline
@@ -13,7 +18,7 @@
1318
* src/attributes.cpp: Allow includes of local files
1419
(e.g. #include "foo.hpp") in sourceCpp
1520
* Rcpp.Rproj: Specify Sweave as Rnw handler for RStudio
16-
* vignettes/*.Rnw: Add driver magic comment and turn off
21+
* vignettes/*.Rnw: Add driver magic comment and turn off
1722
Sweave concordance.
1823
* vignettes/.gitignore: Ignore artifacts of PDF preview
1924

inst/include/Rcpp/Environment.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,15 @@ inline Environment new_env(int size = 29) {
361361
return R_NewHashedEnv(R_EmptyEnv, sizeSEXP);
362362
}
363363

364+
inline Environment new_env(SEXP parent, int size = 29) {
365+
Shield<SEXP> sizeSEXP(Rf_ScalarInteger(size));
366+
Shield<SEXP> parentSEXP(parent);
367+
if (!Rf_isEnvironment(parentSEXP)) {
368+
stop("parent is not an environment");
369+
}
370+
return R_NewHashedEnv(parentSEXP, sizeSEXP);
371+
}
372+
364373

365374
} // namespace Rcpp
366375

0 commit comments

Comments
 (0)