[Rcpp-commits] r731 - in pkg/Rcpp: . src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 17 22:22:16 CET 2010


Author: romain
Date: 2010-02-17 22:22:16 +0100 (Wed, 17 Feb 2010)
New Revision: 731

Modified:
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/src/Environment.cpp
   pkg/Rcpp/src/Rcpp/Environment.h
Log:
Environment gains a find method

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-02-17 21:04:17 UTC (rev 730)
+++ pkg/Rcpp/DESCRIPTION	2010-02-17 21:22:16 UTC (rev 731)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Rcpp R/C++ interface package
-Version: 0.7.7.4
+Version: 0.7.7.5
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Simon Urbanek and David Reiss; based on code written during 

Modified: pkg/Rcpp/src/Environment.cpp
===================================================================
--- pkg/Rcpp/src/Environment.cpp	2010-02-17 21:04:17 UTC (rev 730)
+++ pkg/Rcpp/src/Environment.cpp	2010-02-17 21:22:16 UTC (rev 731)
@@ -23,6 +23,14 @@
 
 namespace Rcpp {
 
+	Environment::not_found::not_found(const std::string& binding_) : binding(binding_){};
+	Environment::not_found::~not_found() throw(){}
+	const char* Environment::not_found::what() const throw(){
+		std::string message( "not found : " ) ;
+		message += binding ;
+		return message.c_str() ;
+	}
+	
     Environment::Environment() : RObject(R_NilValue){}
 
     Environment::Environment( SEXP x = R_GlobalEnv) throw(not_compatible) : RObject(x){
@@ -93,8 +101,7 @@
     }
     
     SEXP Environment::get( const std::string& name) const {
-    	// SEXP res = Rf_findVarInFrame( m_sexp, Rf_install(name.c_str())  ) ;
-    	SEXP res = Rf_findVar( Rf_install(name.c_str()), m_sexp ) ;
+    	SEXP res = Rf_findVarInFrame( m_sexp, Rf_install(name.c_str())  ) ;
     	
     	if( res == R_UnboundValue ) return R_NilValue ;
     	
@@ -105,6 +112,18 @@
     	return res ;
     }
     
+    SEXP Environment::find( const std::string& name) const {
+    	SEXP res = Rf_findVar( Rf_install(name.c_str()), m_sexp ) ;
+    	
+    	if( res == R_UnboundValue ) throw not_found(name) ;
+    	
+    	/* We need to evaluate if it is a promise */
+	if( TYPEOF(res) == PROMSXP){
+    		res = Rf_eval( res, m_sexp ) ;
+    	}
+    	return res ;
+    }
+    
     bool Environment::exists( const std::string& name) const{
     	SEXP res = Rf_findVarInFrame( m_sexp, Rf_install(name.c_str())  ) ;
     	return res != R_UnboundValue ;

Modified: pkg/Rcpp/src/Rcpp/Environment.h
===================================================================
--- pkg/Rcpp/src/Rcpp/Environment.h	2010-02-17 21:04:17 UTC (rev 730)
+++ pkg/Rcpp/src/Rcpp/Environment.h	2010-02-17 21:22:16 UTC (rev 731)
@@ -35,6 +35,15 @@
 class Environment: public RObject{
 public:
 
+	class not_found : public std::exception{
+	public:
+		not_found( const std::string& binding ) ;
+		virtual ~not_found() throw() ;
+		virtual const char* what() const throw();
+	private:
+		std::string binding ;
+	}        ;
+	
    /**
      * Exception thrown when attempting to perform an operation on 
      * a binding and there is no such binding
@@ -319,6 +328,15 @@
     SEXP get(const std::string& name) const ;
     
     /**
+     * Get an object from the environment or one of its
+     * parents
+     *
+     * @param name name of the object
+     *
+     */
+    SEXP find( const std::string& name) const ;
+    
+    /**
      * Indicates if an object called name exists in the 
      * environment
      *



More information about the Rcpp-commits mailing list