[Rcpp-commits] r385 - in pkg: inst inst/unitTests src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 16 14:13:57 CET 2010


Author: romain
Date: 2010-01-16 14:13:57 +0100 (Sat, 16 Jan 2010)
New Revision: 385

Modified:
   pkg/inst/ChangeLog
   pkg/inst/unitTests/runit.environments.R
   pkg/src/Environment.cpp
   pkg/src/Rcpp/Environment.h
Log:
+ Environment::new_child()

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-16 11:26:48 UTC (rev 384)
+++ pkg/inst/ChangeLog	2010-01-16 13:13:57 UTC (rev 385)
@@ -1,5 +1,9 @@
 2010-01-16  Romain Francois <francoisromain at free.fr>
 
+	* src/Rcpp/Environment.h: Environment gains a new_child method
+	to create an environment enclosed by this
+	* inst/unitTests/runit.environments.R: unit test for new_child
+
 	* src/Rcpp/ExpressionVector.h: ExpressionVector gains a
 	convenience methods eval to evaluate itself
 	* inst/unitTests/runit.ExpressionVector.R: added unit tests

Modified: pkg/inst/unitTests/runit.environments.R
===================================================================
--- pkg/inst/unitTests/runit.environments.R	2010-01-16 11:26:48 UTC (rev 384)
+++ pkg/inst/unitTests/runit.environments.R	2010-01-16 13:13:57 UTC (rev 385)
@@ -330,3 +330,13 @@
 	checkEquals( funx(), asNamespace("Rcpp") , msg = "cached Rcpp namespace" )
 }
 
+test.environment.child <- function(){
+	funx <- cfunction(signature(), '
+	Environment global_env = Environment::global_env() ;
+	return global_env.new_child(false) ;
+	', Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+	checkEquals( parent.env(funx()), globalenv(), 
+		msg = "" )
+}
+
+

Modified: pkg/src/Environment.cpp
===================================================================
--- pkg/src/Environment.cpp	2010-01-16 11:26:48 UTC (rev 384)
+++ pkg/src/Environment.cpp	2010-01-16 13:13:57 UTC (rev 385)
@@ -322,5 +322,13 @@
     	    return RCPP_NAMESPACE ;
     }
     
+    Environment Environment::new_child(bool hashed) {
+    	    return Environment( Evaluator::run( 
+    	    	    Rf_lcons( Rf_install("new.env"), 
+    	    	    	    Rf_cons(Rf_ScalarLogical(hashed), 
+    	    	    	    	    Rf_cons(m_sexp,R_NilValue)) ) ) );
+    }
+    
+    
 } // namespace Rcpp
 

Modified: pkg/src/Rcpp/Environment.h
===================================================================
--- pkg/src/Rcpp/Environment.h	2010-01-16 11:26:48 UTC (rev 384)
+++ pkg/src/Rcpp/Environment.h	2010-01-16 13:13:57 UTC (rev 385)
@@ -440,6 +440,11 @@
      */
     Environment parent() const throw() ;
     
+    /**
+     * creates a new environment whose this is the parent
+     */
+    Environment new_child(bool hashed) ; 
+    
 private:
 	/* we cache the Rcpp namespace environment since
 	it is used many times internally */



More information about the Rcpp-commits mailing list