Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2015-02-19 Lionel Henry <lionel.hry@gmail.com>

* inst/include/Rcpp/Environment.h Allow new_env() to create an
environment with a specified parent

2015-02-19 JJ Allaire <jj@rstudio.org>

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

Expand Down
9 changes: 9 additions & 0 deletions inst/include/Rcpp/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,15 @@ inline Environment new_env(int size = 29) {
return R_NewHashedEnv(R_EmptyEnv, sizeSEXP);
}

inline Environment new_env(SEXP parent, int size = 29) {
Shield<SEXP> sizeSEXP(Rf_ScalarInteger(size));
Shield<SEXP> parentSEXP(parent);
if (!Rf_isEnvironment(parentSEXP)) {
stop("parent is not an environment");
}
return R_NewHashedEnv(parentSEXP, sizeSEXP);
}


} // namespace Rcpp

Expand Down
8 changes: 8 additions & 0 deletions inst/unitTests/cpp/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@ Environment runit_child(){
return global_env.new_child(false) ;
}

// [[Rcpp::export]]
Environment runit_new_env_default() {
return Rcpp::new_env();
}

// [[Rcpp::export]]
Environment runit_new_env_parent(SEXP env) {
return Rcpp::new_env(env);
}
5 changes: 5 additions & 0 deletions inst/unitTests/runit.environments.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,10 @@ if (.runThisTest) {
checkEquals( parent.env(runit_child()), globalenv(), msg = "child environment" )
}

test.environment.new_env <- function() {
env <- new.env()
checkIdentical(parent.env(runit_new_env_default()), emptyenv(), msg = "new environment with default parent")
checkIdentical(parent.env(runit_new_env_parent(env)), env, msg = "new environment with specified parent")
}

}