[Rcpp-commits] r1848 - in pkg/Rcpp: R inst/doc/Rcpp-modules

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 9 14:34:38 CEST 2010


Author: romain
Date: 2010-07-09 14:34:38 +0200 (Fri, 09 Jul 2010)
New Revision: 1848

Modified:
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
Log:
the S4 class name is now obfuscated

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-07-09 12:04:21 UTC (rev 1847)
+++ pkg/Rcpp/R/Module.R	2010-07-09 12:34:38 UTC (rev 1848)
@@ -138,11 +138,11 @@
 	}
 	classes <- .Call( "Module__classes_info", xp, PACKAGE = "Rcpp" )
 	if( length( classes ) ){
-		clnames <- names( classes )
 		for( i in seq_along(classes) ){
 			CLASS <- classes[[i]]
-			setClass( clnames[i], contains = "C++Object", where = where )
-			setMethod( "initialize", clnames[i], function(.Object, ...){
+			clname <- as.character(CLASS)
+			setClass( clname, contains = "C++Object", where = where )
+			setMethod( "initialize",clname, function(.Object, ...){
 				.Object <- callNextMethod()
 				if( .Call( "CppObject__needs_init", .Object at pointer, PACKAGE = "Rcpp" ) ){
 					out <- new_CppObject_xp( CLASS, ... )
@@ -155,13 +155,13 @@
 			
 			METHODS <- .Call( "CppClass__methods" , CLASS at pointer , PACKAGE = "Rcpp" )
 			if( "[[" %in% METHODS ){
-				setMethod( "[[", clnames[i], function(x, i, j, ...){
+				setMethod( "[[", clname, function(x, i, j, ...){
 					MethodInvoker( x, "[[" )( i )
 				}, where = where )
 			}
 			
 			if( "[[<-" %in% METHODS ){
-				setReplaceMethod( "[[", clnames[i], function(x, i, j, ..., exact = TRUE, value ){
+				setReplaceMethod( "[[", clname, function(x, i, j, ..., exact = TRUE, value ){
 					MethodInvoker( x, "[[<-" )( i, value )
 					x
 				}, where = where )

Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-07-09 12:04:21 UTC (rev 1847)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-07-09 12:34:38 UTC (rev 1848)
@@ -404,12 +404,16 @@
 \subsubsection{S4 dispatch}
 
 When a \proglang{C++} class is exposed by the \texttt{class\_} template,
-a new S4 class is registered as well. This allows implementation of \proglang{R}-level
+a new S4 class is registered as well. The name of the S4 class is 
+obfuscated in order to avoid name clashes (i.e. two modules exposing the 
+same class). 
+
+This allows implementation of \proglang{R}-level
 (S4) dispatch. For example, one might implement the \texttt{show}
 method for \proglang{C++} \texttt{World} objects:
 
 <<eval=FALSE>>=
-setMethod( "show", "World", function(object){
+setMethod( "show", yada$World , function(object){
 	msg <- paste( "World object with message : ", object$greet() )
 	writeLines( msg )
 } )



More information about the Rcpp-commits mailing list