[Rcpp-commits] r2118 - pkg/Rcpp/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 16 18:27:32 CEST 2010


Author: romain
Date: 2010-09-16 18:27:32 +0200 (Thu, 16 Sep 2010)
New Revision: 2118

Modified:
   pkg/Rcpp/src/Reference.cpp
Log:
impl of Reference::FieldProxy::set using a callback to R $<- operator

Modified: pkg/Rcpp/src/Reference.cpp
===================================================================
--- pkg/Rcpp/src/Reference.cpp	2010-09-16 15:29:28 UTC (rev 2117)
+++ pkg/Rcpp/src/Reference.cpp	2010-09-16 16:27:32 UTC (rev 2118)
@@ -85,7 +85,7 @@
     	
     	SEXP call = ::Rf_lcons( 
     	    R_DollarSymbol, 
-    	    Rf_cons( asSexp(), 
+    	    Rf_cons( const_cast<Reference&>(parent).asSexp() , 
     	        Rf_cons( 
     	            Rf_mkString( field_name.c_str() ),
     	            R_NilValue 
@@ -96,15 +96,16 @@
     
     void Reference::FieldProxy::set( SEXP x) const {
     	// TODO: set the field
-        
-        // // the SEXP might change (.Data)
-    	// SEXP new_obj = PROTECT( R_do_slot_assign( 
-    	// 	parent, 
-    	// 	Rf_install( slot_name.c_str() ), 
-    	// 	x
-    	// 	) ) ;
-    	// const_cast<RObject&>(parent).setSEXP( new_obj ) ;
-    	// UNPROTECT(1) ;  
+        SEXP call = ::Rf_lcons( 
+    	    Rf_install( "$<-") , 
+    	    Rf_cons( const_cast<Reference&>(parent).asSexp() , 
+    	        Rf_cons( 
+    	            Rf_mkString( field_name.c_str() ),
+    	            Rf_cons( 
+    	               x,
+    	               R_NilValue 
+    	            ) ) ) ) ;
+    	const_cast<Reference&>(parent).setSEXP( Rf_eval( call, R_GlobalEnv ) );	            
     }
 
 	



More information about the Rcpp-commits mailing list