00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <Rcpp/Evaluator.h>
00023 #include <Rcpp/Environment.h>
00024
00025 namespace Rcpp {
00026
00027 Evaluator::Evaluator( SEXP expression = R_NilValue) :
00028 expression(expression),
00029 error_occured(false),
00030 result(R_NilValue),
00031 error(R_NilValue) {}
00032
00033 Evaluator::~Evaluator(){}
00034
00035 void Evaluator::run(SEXP env ){
00036 Environment rcpp = Environment::namespace_env("Rcpp") ;
00037 SEXP call = Rf_lang3( Rf_install("protectedEval"), expression, env ) ;
00038 result = wrap( Rf_eval( call, rcpp ) );
00039 result.preserve() ;
00040 error_occured = LOGICAL( Rf_eval( Rf_lang1( Rf_install("errorOccured")) , rcpp) )[0] ;
00041 if( error_occured ){
00042 error = wrap( Rf_eval( Rf_lang1(Rf_install("getCurrentError")) , rcpp) );
00043 error.preserve() ;
00044 }
00045 }
00046
00047 }