[Rcpp-commits] r383 - 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 12:14:38 CET 2010
Author: romain
Date: 2010-01-16 12:14:38 +0100 (Sat, 16 Jan 2010)
New Revision: 383
Modified:
pkg/inst/ChangeLog
pkg/inst/unitTests/runit.ExpressionVector.R
pkg/src/ExpressionVector.cpp
pkg/src/Rcpp/ExpressionVector.h
Log:
+ExpressionVector::eval()
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2010-01-16 10:50:53 UTC (rev 382)
+++ pkg/inst/ChangeLog 2010-01-16 11:14:38 UTC (rev 383)
@@ -1,6 +1,11 @@
2010-01-16 Romain Francois <francoisromain at free.fr>
* src/Rcpp/ExpressionVector.h: ExpressionVector gains a
+ convenience methods eval to evaluate itself
+ * inst/unitTests/runit.ExpressionVector.R: added unit tests
+ for ExpressionVector::eval
+
+ * src/Rcpp/ExpressionVector.h: ExpressionVector gains a
constructor ExpressionVector( const std::string& ) that
parses the string as R code
* inst/unitTests/runit.ExpressionVector.R: added unit tests
Modified: pkg/inst/unitTests/runit.ExpressionVector.R
===================================================================
--- pkg/inst/unitTests/runit.ExpressionVector.R 2010-01-16 10:50:53 UTC (rev 382)
+++ pkg/inst/unitTests/runit.ExpressionVector.R 2010-01-16 11:14:38 UTC (rev 383)
@@ -65,5 +65,13 @@
return code ;',
Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
checkException( funx(), msg = "parse error" )
-
}
+
+test.ExpressionVector.eval <- function(){
+ funx <- cfunction(signature(), '
+ ExpressionVector code( "local( { y <- sample(1:10); sort(y) })" ) ;
+ return code.eval() ;',
+ Rcpp=TRUE, verbose=FALSE, includes = "using namespace Rcpp;" )
+ checkEquals( funx(), 1:10, msg = "ExpressionVector::eval" )
+}
+
Modified: pkg/src/ExpressionVector.cpp
===================================================================
--- pkg/src/ExpressionVector.cpp 2010-01-16 10:50:53 UTC (rev 382)
+++ pkg/src/ExpressionVector.cpp 2010-01-16 11:14:38 UTC (rev 383)
@@ -108,5 +108,13 @@
return Proxy(*this, i ) ;
}
+SEXP ExpressionVector::eval() throw(Evaluator::eval_error){
+ return eval( R_GlobalEnv ) ;
+
+}
+SEXP ExpressionVector::eval(const Environment& env) throw(Evaluator::eval_error){
+ return Evaluator::run( Rf_lcons( Rf_install( "eval" ) , Rf_cons( m_sexp, R_NilValue) ) , R_GlobalEnv ) ;
+}
+
} // namespace
Modified: pkg/src/Rcpp/ExpressionVector.h
===================================================================
--- pkg/src/Rcpp/ExpressionVector.h 2010-01-16 10:50:53 UTC (rev 382)
+++ pkg/src/Rcpp/ExpressionVector.h 2010-01-16 11:14:38 UTC (rev 383)
@@ -25,6 +25,7 @@
#include <RcppCommon.h>
#include <Rcpp/RObject.h>
#include <Rcpp/VectorBase.h>
+#include <Rcpp/Evaluator.h>
#ifdef HAS_INIT_LISTS
#include <initializer_list>
@@ -70,6 +71,9 @@
ExpressionVector(int size) ;
ExpressionVector(const std::string& code) throw(parse_error) ;
+ SEXP eval() throw(Evaluator::eval_error) ;
+ SEXP eval(const Environment& env) throw(Evaluator::eval_error);
+
#ifdef HAS_INIT_LISTS
ExpressionVector( std::initializer_list<RObject> list ) ;
#endif
More information about the Rcpp-commits
mailing list