[Rcpp-commits] r2142 - in pkg/Rcpp: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 22 13:01:50 CEST 2010


Author: romain
Date: 2010-09-22 13:01:50 +0200 (Wed, 22 Sep 2010)
New Revision: 2142

Modified:
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/ChangeLog
Log:
restoring [[ and [[<- as regular methods

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-09-22 10:29:48 UTC (rev 2141)
+++ pkg/Rcpp/R/Module.R	2010-09-22 11:01:50 UTC (rev 2142)
@@ -173,6 +173,24 @@
         assign(".module", xp, envir = fields)
         assign(".CppClassName", clname, envir = fields)
         generators[[clname]] <- generator
+        
+        # [romain] : should this be promoted to reference classes
+        #            perhaps with better handling of j and ... arguments
+        if( any( grepl( "^[[]", names(CLASS at methods) ) ) ){
+            if( "[[" %in% names( CLASS at methods ) ){
+                setMethod( "[[", clname, function(x, i, j, ..., exact = TRUE){
+                    x$`[[`( i )
+                }, where = where )
+            }
+            
+            if( "[[<-" %in% names( CLASS at methods ) ){
+                setReplaceMethod( "[[", clname, function(x, i, j, ..., exact = TRUE, value){
+                    x$`[[<-`( i, value )
+                    x
+                } , where = where )
+            }
+            
+        }
     }
     module$refClassGenerators <- generators
     module

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-09-22 10:29:48 UTC (rev 2141)
+++ pkg/Rcpp/inst/ChangeLog	2010-09-22 11:01:50 UTC (rev 2142)
@@ -1,3 +1,8 @@
+2010-09-22  Romain Francois <romain at r-enthusiasts.com>
+
+    * R/Module.R: set [[ and [[<- as regular methods too, which restores previous
+    behavior
+
 2010-09-17  Romain Francois <romain at r-enthusiasts.com>
 
     * src/Reference.cpp: new objects are created via a callback to R's new



More information about the Rcpp-commits mailing list