[Rcpp-devel] [Rcpp-commits] r251 - in pkg: inst inst/examples/RcppInline inst/unitTests src src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jan 1 09:25:56 CET 2010


Author: romain
Date: 2010-01-01 09:25:55 +0100 (Fri, 01 Jan 2010)
New Revision: 251

Modified:
   pkg/inst/ChangeLog
   pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r
   pkg/inst/examples/RcppInline/RcppSexpTests.r
   pkg/inst/examples/RcppInline/external_pointer.r
   pkg/inst/unitTests/runit.RObject.R
   pkg/inst/unitTests/runit.XPTr.R
   pkg/inst/unitTests/runit.environments.R
   pkg/src/Evaluator.cpp
   pkg/src/RObject.cpp
   pkg/src/Rcpp/RObject.h
Log:
replace RObject::RObject constructors with RObject::wrap functions

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/ChangeLog	2010-01-01 08:25:55 UTC (rev 251)
@@ -1,12 +1,20 @@
 2010-01-01  Romain Francois <francoisromain at free.fr>
 
+	* pkg/src/Rcpp/RObject.h: RObject::RObject constructors are 
+	replaced by the Rcpp::wrap set of functions. Currently the wrap 
+	functions make a RObject object but it is likely that as new
+	classes become available in the new API, wrap will return 
+	instances of classes that extend RObject.
+	
 	* pkg/src/Rcpp/RObject.h: s/protect/preserve/, added methods
 	isPreserved and forgetPreserve
-	
-	* pkg/src/Rcpp/XPtr.h 
-	* pkg/src/RObject.cpp
-	* pkg/src/Evaluator.cpp
 
+	* ** : adapted examples, code, and unit tests to reflect both 
+	above items
+
+2010-01-01  Romain Francois <francoisromain at free.fr>
+
+
 2009-12-31  Romain Francois <francoisromain at free.fr>
 
 	* src/Rcpp/Evaluator.h : new class Rcpp::Evaluator that eases

Modified: pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r
===================================================================
--- pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/examples/RcppInline/RcppInlineWithLibsExamples.r	2010-01-01 08:25:55 UTC (rev 251)
@@ -56,7 +56,7 @@
 
     ## now use Rcpp to pass down a parameter for the seed
     gslrng <- '
-    int seed = Rcpp::RObject(par).asInt();
+    int seed = Rcpp::wrap(par).asInt();
 
     gsl_rng *r;
     gsl_rng_env_setup();
@@ -74,7 +74,7 @@
     #endif
 
     gsl_rng_free(r);
-    return Rcpp::RObject(v) ;
+    return Rcpp::wrap(v) ;
     '
 
     ## turn into a function that R can call
@@ -103,8 +103,8 @@
 
     ## now use Rcpp to pass down a parameter for the seed, and a vector size
     gslrng <- '
-    int seed = Rcpp::RObject(s).asInt();
-    int len = Rcpp::RObject(n).asInt();
+    int seed = Rcpp::wrap(s).asInt();
+    int len = Rcpp::wrap(n).asInt();
 
     gsl_rng *r;
     gsl_rng_env_setup();
@@ -118,7 +118,7 @@
     }
     gsl_rng_free(r);
 
-    return Rcpp::RObject(v) ;
+    return Rcpp::wrap(v) ;
     '
 
     ## turn into a function that R can call

Modified: pkg/inst/examples/RcppInline/RcppSexpTests.r
===================================================================
--- pkg/inst/examples/RcppInline/RcppSexpTests.r	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/examples/RcppInline/RcppSexpTests.r	2010-01-01 08:25:55 UTC (rev 251)
@@ -22,9 +22,9 @@
 
 cat("===Doubles\n")
 foo <- '
-        double d = Rcpp::RObject(x).asDouble();
+        double d = Rcpp::wrap(x).asDouble();
 	std::cout << "Returning twice the value of " << d << " : ";
-	return(Rcpp::RObject( 2*d ) );
+	return(Rcpp::wrap( 2*d ) );
         '
 funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 cat(funx(x=2.123), "\n")
@@ -35,9 +35,9 @@
 
 cat("\n===Int\n")
 foo <- '
-        int i = Rcpp::RObject(x).asInt();
+        int i = Rcpp::wrap(x).asInt();
 	std::cout << "Returning twice the value of " << i << " : ";
-	return(Rcpp::RObject( 2*i ) );
+	return(Rcpp::wrap( 2*i ) );
         '
 funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 cat(funx(x=2), "\n")
@@ -47,18 +47,18 @@
 
 cat("\n===String\n")
 foo <- '
-        std::string s = Rcpp::RObject(x).asStdString();
+        std::string s = Rcpp::wrap(x).asStdString();
 	std::cout << "Returning twice the value of " << s << " : ";
-	return(Rcpp::RObject( s+s ) );
+	return(Rcpp::wrap( s+s ) );
         '
 funx <- cfunction(signature(x="character"), foo, Rcpp=TRUE, verbose=FALSE)
 cat(funx(x="abc"), "\n")
 
 cat("\n===Raw (bytes)\n")
 foo <- '
-        Rbyte i = Rcpp::RObject(x).asRaw();
+        Rbyte i = Rcpp::wrap(x).asRaw();
 	std::cout << "Returning twice the value of " << (int)i << " : ";
-	return(Rcpp::RObject( (Rbyte)(2*i) ) );
+	return(Rcpp::wrap( (Rbyte)(2*i) ) );
         '
 funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 cat( funx(x=2), "\n")
@@ -69,9 +69,9 @@
 
 cat("\n=== logical \n")
 foo <- '
-bool b = Rcpp::RObject(x).asBool();
+bool b = Rcpp::wrap(x).asBool();
 std::cout << "flip  " << ( b ? "TRUE" : "FALSE" ) << " : ";
-return(Rcpp::RObject( !b ));
+return(Rcpp::wrap( !b ));
 '
 funx <- cfunction(signature(x="logical"), foo, Rcpp=TRUE, verbose=FALSE)
 cat( res <- funx(x=TRUE) , "\n")  ; stopifnot( !res )
@@ -90,7 +90,7 @@
 
 cat("\n===Int Vector via RcppResultSet.getSEXP\n")
 foo <- '
-        std::vector<int> iv = Rcpp::RObject(x).asStdVectorInt();
+        std::vector<int> iv = Rcpp::wrap(x).asStdVectorInt();
 	std::cout << "Returning twice the value of vector : ";
         for (size_t i=0; i<iv.size(); i++) {
             iv[i] = 2*iv[i];
@@ -108,12 +108,12 @@
 
 cat("\n===Int Vector\n")
 foo <- '
-        std::vector<int> iv = Rcpp::RObject(x).asStdVectorInt();
+        std::vector<int> iv = Rcpp::wrap(x).asStdVectorInt();
 	std::cout << "Returning twice the value of vector : ";
         for (size_t i=0; i<iv.size(); i++) {
             iv[i] = 2*iv[i];
         }
-	return(Rcpp::RObject( iv ) );
+	return(Rcpp::wrap( iv ) );
         '
 funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 print(funx(x=2:5+.1))
@@ -125,12 +125,12 @@
 
 cat("\n===Double Vector\n")
 foo <- '
-        std::vector<double> iv = Rcpp::RObject(x).asStdVectorDouble();
+        std::vector<double> iv = Rcpp::wrap(x).asStdVectorDouble();
 	std::cout << "Returning twice the value of vector : ";
         for (size_t i=0; i<iv.size(); i++) {
             iv[i] = 2*iv[i];
         }
- 	return(Rcpp::RObject( iv ));
+ 	return(Rcpp::wrap( iv ));
         '
 funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 print(funx(x=0.1+2:5))
@@ -141,12 +141,12 @@
 
 cat("\n===Raw Vector\n")
 foo <- '
-        std::vector<Rbyte> iv = Rcpp::RObject(x).asStdVectorRaw();
+        std::vector<Rbyte> iv = Rcpp::wrap(x).asStdVectorRaw();
 	std::cout << "Returning twice the value of vector : ";
         for (size_t i=0; i<iv.size(); i++) {
             iv[i] = 2*iv[i];
         }
- 	return(Rcpp::RObject( iv ));
+ 	return(Rcpp::wrap( iv ));
         '
 funx <- cfunction(signature(x="raw"), foo, Rcpp=TRUE, verbose=FALSE)
 print(funx(x=as.raw(0:9)))
@@ -157,12 +157,12 @@
 
 cat("\n=== vector<bool>\n")
 foo <- '
-std::vector<bool> bv = Rcpp::RObject(x).asStdVectorBool();
+std::vector<bool> bv = Rcpp::wrap(x).asStdVectorBool();
 std::cout << "Flip the value of vector : ";
 for (size_t i=0; i<bv.size(); i++) {
     bv[i].flip() ;
 }
-return(Rcpp::RObject( bv ));
+return(Rcpp::wrap( bv ));
 '
 funx <- cfunction(signature(x="logical"), foo, Rcpp=TRUE, verbose=FALSE)
 print(funx(x=c(TRUE,FALSE)))
@@ -176,12 +176,12 @@
 
 cat("\n===String Vector\n")
 foo <- '
-        std::vector<std::string> iv = Rcpp::RObject(x).asStdVectorString();
+        std::vector<std::string> iv = Rcpp::wrap(x).asStdVectorString();
 	std::cout << "Returning twice the value of vector : ";
         for (size_t i=0; i<iv.size(); i++) {
             iv[i] = iv[i] + iv[i];
         }
- 	return(Rcpp::RObject( iv ));
+ 	return(Rcpp::wrap( iv ));
         '
 funx <- cfunction(signature(x="character"), foo, Rcpp=TRUE, verbose=FALSE)
 print(funx(x=c("foo", "bar")))
@@ -193,7 +193,7 @@
 iv.insert( 0 ) ;
 iv.insert( 1 ) ;
 iv.insert( 0 ) ;
-return Rcpp::RObject( iv );'
+return Rcpp::wrap( iv );'
 funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>" )
 print(res <- funx())
 stopifnot( identical( res, 0:1 ) )
@@ -204,7 +204,7 @@
 ds.insert( 0.0 );
 ds.insert( 1.0 );
 ds.insert( 0.0 );
-return(Rcpp::RObject( ds )); '
+return(Rcpp::wrap( ds )); '
 funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>")
 print( res <- funx() )
 stopifnot( identical( res, as.numeric(0:1)))
@@ -215,7 +215,7 @@
 bs.insert( (Rbyte)0 ) ;
 bs.insert( (Rbyte)1 ) ;
 bs.insert( (Rbyte)0 ) ;
-return(Rcpp::RObject( bs )); '
+return(Rcpp::wrap( bs )); '
 funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>")
 print( res <- funx() )
 stopifnot( identical( res, as.raw(0:1)))
@@ -226,7 +226,7 @@
 ss.insert( "foo" ) ;
 ss.insert( "bar" ) ;
 ss.insert( "foo" ) ;
-return(Rcpp::RObject( ss )); '
+return(Rcpp::wrap( ss )); '
 funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, include = "#include <set>" )
 print( res <- funx() )
 stopifnot( identical( res, c("bar","foo")) )
@@ -236,29 +236,29 @@
 
 funx <- cfunction(
 	signature(x="data.frame"), '
-std::vector<std::string> iv = Rcpp::RObject(x).attributeNames();
-return(Rcpp::RObject( iv ));
+std::vector<std::string> iv = Rcpp::wrap(x).attributeNames();
+return(Rcpp::wrap( iv ));
 ', Rcpp=TRUE, verbose=FALSE)
 res <- funx( iris )
 stopifnot( all( c("names", "row.names", "class" ) %in% res ) )
 
 funx <- cfunction(signature(x="data.frame"), '
-bool has_class = Rcpp::RObject(x).hasAttribute( "class" ) ;
-return Rcpp::RObject( has_class ) ;
+bool has_class = Rcpp::wrap(x).hasAttribute( "class" ) ;
+return Rcpp::wrap( has_class ) ;
 ', Rcpp=TRUE, verbose=FALSE)
 res <- funx( iris )
 stopifnot( res )
 
 funx <- cfunction(signature(x="data.frame"), '
-return Rcpp::RObject(x).attr( "row.names" ) ;
+return Rcpp::wrap(x).attr( "row.names" ) ;
 ', Rcpp=TRUE, verbose=FALSE)
 res <- funx( iris )
 stopifnot( identical(res, 1:150) )
 
 #============ NULL
 funx <- cfunction(signature(x="ANY"), '
-bool is_null = Rcpp::RObject(x).isNULL() ;
-return Rcpp::RObject( is_null ) ;
+bool is_null = Rcpp::wrap(x).isNULL() ;
+return Rcpp::wrap( is_null ) ;
 ', Rcpp=TRUE, verbose=FALSE)
 res <- funx( iris )
 stopifnot( !res )

Modified: pkg/inst/examples/RcppInline/external_pointer.r
===================================================================
--- pkg/inst/examples/RcppInline/external_pointer.r	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/examples/RcppInline/external_pointer.r	2010-01-01 08:25:55 UTC (rev 251)
@@ -51,7 +51,7 @@
 	Rcpp::XPtr< std::vector<int> > p(x) ;
 	
 	/* just return the front of the vector as a SEXP */
-	return( Rcpp::RObject( p->front() ) ) ;
+	return( Rcpp::wrap( p->front() ) ) ;
 ', Rcpp=TRUE, verbose=FALSE)
 front <- funx(xp)
 stopifnot( identical( front, 1L ) )

Modified: pkg/inst/unitTests/runit.RObject.R
===================================================================
--- pkg/inst/unitTests/runit.RObject.R	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/unitTests/runit.RObject.R	2010-01-01 08:25:55 UTC (rev 251)
@@ -25,8 +25,8 @@
 
 test.RObject.asDouble <- function(){
 	foo <- '
-	double d = Rcpp::RObject(x).asDouble();
-	return(Rcpp::RObject( 2*d ) );
+	double d = Rcpp::wrap(x).asDouble();
+	return(Rcpp::wrap( 2*d ) );
 	'
 	funx <- cfunction(signature(x="numeric"), foo, 
 		Rcpp=TRUE, verbose=FALSE)
@@ -39,8 +39,8 @@
 
 test.RObject.asInt <- function(){
 	foo <- '
-	int i = Rcpp::RObject(x).asInt();
-	return(Rcpp::RObject( 2*i ) ); '
+	int i = Rcpp::wrap(x).asInt();
+	return(Rcpp::wrap( 2*i ) ); '
 	funx <- cfunction(signature(x="numeric"), foo, 
 		Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(2.123), 4L, msg = "RObject.asInt()" )
@@ -54,8 +54,8 @@
 
 test.RObject.asStdString <- function(){
 	foo <- '
-	std::string s = Rcpp::RObject(x).asStdString();
-	return(Rcpp::RObject( s+s ) );'
+	std::string s = Rcpp::wrap(x).asStdString();
+	return(Rcpp::wrap( s+s ) );'
 	funx <- cfunction(signature(x="character"), foo, 
 		Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx("abc"), "abcabc", msg = "RObject.asStdString()" )
@@ -70,8 +70,8 @@
 
 test.RObject.asRaw <- function(){
 	foo <- '
-	Rbyte i = Rcpp::RObject(x).asRaw();
-	return(Rcpp::RObject( (Rbyte)(2*i) ) ); '
+	Rbyte i = Rcpp::wrap(x).asRaw();
+	return(Rcpp::wrap( (Rbyte)(2*i) ) ); '
 	funx <- cfunction(signature(x="raw"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(1L), as.raw(2L), msg = "RObject.asRaw(integer)" )
 	checkEquals( funx(1.3), as.raw(2L), msg = "RObject.asRaw(numeric)" )
@@ -88,8 +88,8 @@
 
 test.RObject.asLogical <- function(){
 	foo <- '
-	bool b = Rcpp::RObject(x).asBool();
-	return(Rcpp::RObject( !b ));'
+	bool b = Rcpp::wrap(x).asBool();
+	return(Rcpp::wrap( !b ));'
 	funx <- cfunction(signature(x="logical"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkTrue( !funx(TRUE), msg = "RObject::asBool(TRUE) -> true" )
 	checkTrue( funx(FALSE), msg = "RObject::asBool(FALSE) -> false" )
@@ -113,7 +113,7 @@
 
 test.RObject.asStdVectorIntResultsSet <- function(){
 	foo <- '
-		std::vector<int> iv = Rcpp::RObject(x).asStdVectorInt();
+		std::vector<int> iv = Rcpp::wrap(x).asStdVectorInt();
 		for (size_t i=0; i<iv.size(); i++) {
     	    iv[i] = 2*iv[i];
     	}
@@ -130,11 +130,11 @@
 
 test.RObject.asStdVectorInt <- function(){
 	foo <- '
-		std::vector<int> iv = Rcpp::RObject(x).asStdVectorInt();
+		std::vector<int> iv = Rcpp::wrap(x).asStdVectorInt();
 		for (size_t i=0; i<iv.size(); i++) {
     	    iv[i] = 2*iv[i];
     	}
-		return(Rcpp::RObject( iv ) );'
+		return(Rcpp::wrap( iv ) );'
 	funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(x=2:5), 2:5*2L, msg = "RObject(integer).asStdVectorInt" )
     checkEquals( funx(x=2:5+.1), 2:5*2L, msg = "RObject(numeric).asStdVectorInt" )
@@ -146,11 +146,11 @@
 
 test.RObject.asStdVectorDouble <- function(){
 	foo <- '
-		std::vector<double> iv = Rcpp::RObject(x).asStdVectorDouble();
+		std::vector<double> iv = Rcpp::wrap(x).asStdVectorDouble();
 		for (size_t i=0; i<iv.size(); i++) {
 	        iv[i] = 2*iv[i];
 	    }
-	 	return(Rcpp::RObject( iv ));'
+	 	return(Rcpp::wrap( iv ));'
 	funx <- cfunction(signature(x="numeric"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(x=0.1+2:5), 2*(0.1+2:5), msg = "RObject(numeric).asStdVectorDouble" )
 	checkEquals( funx(x=2:5), 2*(2:5), msg = "RObject(integer).asStdVectorDouble" )
@@ -162,11 +162,11 @@
 
 test.RObject.asStdVectorRaw <- function(){
 	foo <- '
-    	std::vector<Rbyte> iv = Rcpp::RObject(x).asStdVectorRaw();
+    	std::vector<Rbyte> iv = Rcpp::wrap(x).asStdVectorRaw();
 		for (size_t i=0; i<iv.size(); i++) {
     	    iv[i] = 2*iv[i];
     	}
- 		return(Rcpp::RObject( iv ));'
+ 		return(Rcpp::wrap( iv ));'
 	funx <- cfunction(signature(x="raw"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(x=as.raw(0:9)), as.raw(2*(0:9)), msg = "RObject(raw).asStdVectorRaw" )
 	checkEquals( funx(x=0:9), as.raw(2*(0:9)), msg = "RObject(integer).asStdVectorRaw" )
@@ -178,11 +178,11 @@
 
 test.RObject.asStdVectorBool <- function(){
 	foo <- '
-		std::vector<bool> bv = Rcpp::RObject(x).asStdVectorBool();
+		std::vector<bool> bv = Rcpp::wrap(x).asStdVectorBool();
 		for (size_t i=0; i<bv.size(); i++) {
 		    bv[i].flip() ;
 		}
-		return(Rcpp::RObject( bv ));'
+		return(Rcpp::wrap( bv ));'
 	funx <- cfunction(signature(x="logical"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(x=c(TRUE,FALSE)), c(FALSE, TRUE), msg = "RObject(logical).asStdVectorBool" )
 	checkEquals( funx(x=c(1L, 0L)), c(FALSE, TRUE), msg = "RObject(integer).asStdVectorBool" )
@@ -194,11 +194,11 @@
 
 test.RObject.asStdVectorString <- function(){
 	foo <- '
-    	std::vector<std::string> iv = Rcpp::RObject(x).asStdVectorString();
+    	std::vector<std::string> iv = Rcpp::wrap(x).asStdVectorString();
 		for (size_t i=0; i<iv.size(); i++) {
     	    iv[i] = iv[i] + iv[i];
     	}
- 	return(Rcpp::RObject( iv ));'
+ 	return(Rcpp::wrap( iv ));'
 	funx <- cfunction(signature(x="character"), foo, Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx(c("foo", "bar")), c("foofoo", "barbar"), msg = "RObject(character).asStdVectorString" )
 	checkException( funx(1L), msg = "RObject(integer).asStdVectorString -> exception" )
@@ -214,7 +214,7 @@
 		iv.insert( 0 ) ;
 		iv.insert( 1 ) ;
 		iv.insert( 0 ) ;
-		return Rcpp::RObject( iv );'
+		return Rcpp::wrap( iv );'
 	funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>" )
 	checkEquals( funx(), c(0L, 1L), msg = "RObject( set<int> )" )
 }
@@ -225,7 +225,7 @@
 		ds.insert( 0.0 );
 		ds.insert( 1.0 );
 		ds.insert( 0.0 );
-		return(Rcpp::RObject( ds )); '
+		return(Rcpp::wrap( ds )); '
 	funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>")
 	checkEquals( funx(), as.numeric(0:1), msg = "RObject( set<double>" )
 }
@@ -236,7 +236,7 @@
 		bs.insert( (Rbyte)0 ) ;
 		bs.insert( (Rbyte)1 ) ;
 		bs.insert( (Rbyte)0 ) ;
-		return(Rcpp::RObject( bs )); '
+		return(Rcpp::wrap( bs )); '
 	funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, includes = "#include <set>")
 	checkEquals( funx(), as.raw(0:1), msg = "RObject(set<raw>)" )
 }
@@ -247,38 +247,38 @@
 		ss.insert( "foo" ) ;
 		ss.insert( "bar" ) ;
 		ss.insert( "foo" ) ;
-		return(Rcpp::RObject( ss )); '
+		return(Rcpp::wrap( ss )); '
 	funx <- cfunction(signature(), foo, Rcpp=TRUE, verbose=FALSE, include = "#include <set>" )
 	checkEquals( funx(), c("bar", "foo"), msg = "RObject(set<string>)" )
 }
 
 test.RObject.attributeNames <- function(){
 	funx <- cfunction(signature(x="data.frame"), '
-		std::vector<std::string> iv = Rcpp::RObject(x).attributeNames();
-		return(Rcpp::RObject( iv ));', 
+		std::vector<std::string> iv = Rcpp::wrap(x).attributeNames();
+		return(Rcpp::wrap( iv ));', 
 		Rcpp=TRUE, verbose=FALSE)
 	checkTrue( all( c("names","row.names","class") %in% funx(iris)), msg = "RObject.attributeNames" )
 }
 
 test.RObject.hasAttribute <- function(){
 	funx <- cfunction(signature(x="data.frame"), '
-		bool has_class = Rcpp::RObject(x).hasAttribute( "class" ) ;
-		return Rcpp::RObject( has_class ) ;', 
+		bool has_class = Rcpp::wrap(x).hasAttribute( "class" ) ;
+		return Rcpp::wrap( has_class ) ;', 
 		Rcpp=TRUE, verbose=FALSE)
 	checkTrue( funx( iris ), msg = "RObject.hasAttribute" )
 }
 
 test.RObject.attr <- function(){
 	funx <- cfunction(signature(x="data.frame"), '
-		return Rcpp::RObject(x).attr( "row.names" ) ;
+		return Rcpp::wrap(x).attr( "row.names" ) ;
 		', Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx( iris ), 1:150, msg = "RObject.attr" )
 }
 
 test.RObject.isNULL <- function(){
 	funx <- cfunction(signature(x="ANY"), '
-		bool is_null = Rcpp::RObject(x).isNULL() ;
-		return Rcpp::RObject( is_null ) ;
+		bool is_null = Rcpp::wrap(x).isNULL() ;
+		return Rcpp::wrap( is_null ) ;
 		', Rcpp=TRUE, verbose=FALSE)
 	checkTrue( !funx( iris ), msg = "RObject.isNULL(iris) -> false" )
 	checkTrue( funx(NULL), msg = "RObject.isNULL(NULL) -> true" )

Modified: pkg/inst/unitTests/runit.XPTr.R
===================================================================
--- pkg/inst/unitTests/runit.XPTr.R	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/unitTests/runit.XPTr.R	2010-01-01 08:25:55 UTC (rev 251)
@@ -55,7 +55,7 @@
 		Rcpp::XPtr< std::vector<int> > p(x) ;
 		
 		/* just return the front of the vector as a SEXP */
-		return( Rcpp::RObject( p->front() ) ) ;
+		return( Rcpp::wrap( p->front() ) ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	front <- funx(xp)
 	checkEquals( front, 1L, msg = "check usage of external pointer" )

Modified: pkg/inst/unitTests/runit.environments.R
===================================================================
--- pkg/inst/unitTests/runit.environments.R	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/inst/unitTests/runit.environments.R	2010-01-01 08:25:55 UTC (rev 251)
@@ -48,7 +48,7 @@
 test.environment.get <- function(){
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	return env.get( Rcpp::RObject(name).asStdString() ) ;
+	return env.get( Rcpp::wrap(name).asStdString() ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env( )
@@ -65,8 +65,8 @@
 test.environment.exists <- function(){
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
-	return Rcpp::RObject( env.exists(st) ) ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
+	return Rcpp::wrap( env.exists(st) ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env( )
@@ -83,8 +83,8 @@
 	
 	funx <- cfunction(signature(x="environment", name = "character", object = "ANY" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
-	return Rcpp::RObject( env.assign(st, object) ) ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
+	return Rcpp::wrap( env.assign(st, object) ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env( )
@@ -104,7 +104,7 @@
 test.environment.isLocked <- function(){
 	funx <- cfunction(signature(x="environment" ), '
 	Rcpp::Environment env(x) ;
-	return Rcpp::RObject( env.isLocked() ) ;
+	return Rcpp::wrap( env.isLocked() ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env()
@@ -117,8 +117,8 @@
 	
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
-	return Rcpp::RObject( env.bindingIsActive(st) ) ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
+	return Rcpp::wrap( env.bindingIsActive(st) ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env()
@@ -137,8 +137,8 @@
 	
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
-	return Rcpp::RObject( env.bindingIsLocked(st) ) ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
+	return Rcpp::wrap( env.bindingIsLocked(st) ) ;
 	', Rcpp=TRUE, verbose=FALSE)
 	
 	e <- new.env()
@@ -167,7 +167,7 @@
 test.environment.lockBinding <- function(){
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
 	env.lockBinding( st ) ;
 	return R_NilValue ;
 	', Rcpp=TRUE, verbose=FALSE)
@@ -186,7 +186,7 @@
 test.environment.unlockBinding <- function(){
 	funx <- cfunction(signature(x="environment", name = "character" ), '
 	Rcpp::Environment env(x) ;
-	std::string st = Rcpp::RObject(name).asStdString() ;
+	std::string st = Rcpp::wrap(name).asStdString() ;
 	env.unlockBinding( st ) ;
 	return R_NilValue ;
 	', Rcpp=TRUE, verbose=FALSE)
@@ -229,7 +229,7 @@
 
 test.environment.namespace.env <- function(){
 	funx <- cfunction(signature(env = "character" ),  '
-	std::string st = Rcpp::RObject(env).asStdString() ;
+	std::string st = Rcpp::wrap(env).asStdString() ;
 	return Rcpp::Environment::namespace_env(st); ', Rcpp=TRUE, verbose=FALSE)
 	checkEquals( funx("Rcpp"), asNamespace("Rcpp"), msg = "REnvironment::base_namespace" )
 	checkTrue( 

Modified: pkg/src/Evaluator.cpp
===================================================================
--- pkg/src/Evaluator.cpp	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/src/Evaluator.cpp	2010-01-01 08:25:55 UTC (rev 251)
@@ -35,11 +35,11 @@
 	void Evaluator::run(SEXP env ){
 		Environment rcpp = Environment::namespace_env("Rcpp") ;
 		SEXP call = Rf_lang3( Rf_install("protectedEval"), expression, env ) ;
-		result = RObject( Rf_eval( call, rcpp ) ); 
+		result = wrap( Rf_eval( call, rcpp ) ); 
 		result.preserve() ;
 		error_occured = LOGICAL( Rf_eval( Rf_lang1( Rf_install("errorOccured")) , rcpp) )[0] ;
 		if( error_occured ){
-			error = RObject( Rf_eval( Rf_lang1(Rf_install("getCurrentError")) , rcpp) );
+			error = wrap( Rf_eval( Rf_lang1(Rf_install("getCurrentError")) , rcpp) );
 			error.preserve() ;
 		}
 	}

Modified: pkg/src/RObject.cpp
===================================================================
--- pkg/src/RObject.cpp	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/src/RObject.cpp	2010-01-01 08:25:55 UTC (rev 251)
@@ -24,73 +24,93 @@
 
 namespace Rcpp {
 
-RObject::RObject(const bool & v) {
+RObject wrap(SEXP m_sexp=R_NilValue){
+    return RObject(m_sexp) ;
+}
+	
+RObject wrap(const bool & v){
     logTxt("RObject from bool\n");
-    m_sexp = Rf_ScalarLogical(v);
-    preserve() ;
+    RObject o(Rf_ScalarLogical(v));
+    o.preserve() ;
+    return o ;
 }
 
-RObject::RObject(const double & v) {
+RObject wrap(const double & v){
     logTxt("RObject from double\n");
-    m_sexp = Rf_ScalarReal(v);
-    preserve() ;
+    RObject o(Rf_ScalarReal(v));
+    o.preserve() ;
+    return o ;
 }
 
-RObject::RObject(const int & v) {
+RObject wrap(const int & v){
     logTxt("RObject from int\n");
-    m_sexp = Rf_ScalarInteger(v);
-    preserve() ;
+    RObject o(Rf_ScalarInteger(v));
+    o.preserve() ;
+    return o ;
 }
 
-RObject::RObject(const Rbyte & v) {
+RObject wrap(const Rbyte & v){
     logTxt("RObject from raw\n");
-    m_sexp = Rf_ScalarRaw(v);
-    preserve() ;
+    RObject o(Rf_ScalarRaw(v));
+    o.preserve() ;
+    return o ;
 }
 
-RObject::RObject(const std::string & v) {
+RObject wrap(const std::string & v){
     logTxt("RObject from std::string\n");
-    m_sexp = Rf_mkString(v.c_str());
-    preserve() ;
+    RObject o(Rf_mkString(v.c_str()));
+    o.preserve() ;
+    return o ;
 }
 
-RObject::RObject(const std::vector<bool> & v) {
+RObject wrap(const std::vector<bool> & v){
     logTxt("RObject from bool vector\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(LGLSXP, n);
-    preserve() ;
+    SEXP m_sexp = PROTECT( Rf_allocVector(LGLSXP, n) );
     copy( v.begin(), v.end(), LOGICAL(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ; /* m_sexp now preserved by o */
+    return o ;
 }
 
-RObject::RObject(const std::vector<int> & v) {
+RObject wrap(const std::vector<int> & v){
     logTxt("RObject from int vector\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(INTSXP, n);
-    preserve() ;
+    SEXP m_sexp = PROTECT( Rf_allocVector(INTSXP, n) );
     copy( v.begin(), v.end(), INTEGER(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::vector<double> & v) {
+RObject wrap(const std::vector<double> & v){
     logTxt("RObject from double vector\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(REALSXP, n);
-    preserve() ;
+    SEXP m_sexp = PROTECT( Rf_allocVector(REALSXP, n) );
     copy( v.begin(), v.end(), REAL(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::vector<Rbyte> & v) {
+RObject wrap(const std::vector<Rbyte> & v){
     logTxt("RObject from vector<Rbyte> \n");
     int n = v.size();
-    m_sexp = Rf_allocVector(RAWSXP, n);
-    preserve() ;
+    SEXP m_sexp = PROTECT(Rf_allocVector(RAWSXP, n));
     copy( v.begin(), v.end(), RAW(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::vector<std::string> & v) {
+RObject wrap(const std::vector<std::string> & v){
     logTxt("RObject from std::string vector\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(STRSXP, n);
-    preserve() ;
+    SEXP m_sexp = PROTECT(Rf_allocVector(STRSXP, n));
     int i=0; 
     std::vector<std::string>::const_iterator it = v.begin() ;
     while( i<n ){
@@ -98,39 +118,51 @@
     	i++ ;
     	it++; 
     }
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
 /* sets */
 
-RObject::RObject(const std::set<int> & v) {
+RObject wrap(const std::set<int> & v){
     logTxt("RObject from set<int>\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(INTSXP, n);
-    preserve() ;
+    SEXP m_sexp = Rf_allocVector(INTSXP, n);
     copy( v.begin(), v.end(), INTEGER(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::set<double> & v) {
+RObject wrap(const std::set<double> & v){
     logTxt("RObject from set<double>\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(REALSXP, n);
-    preserve() ;
+    SEXP m_sexp = Rf_allocVector(REALSXP, n);
     copy( v.begin(), v.end(), REAL(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::set<Rbyte> & v) {
+RObject wrap(const std::set<Rbyte> & v){
     logTxt("RObject from set<Rbyte> \n");
     int n = v.size();
-    m_sexp = Rf_allocVector(RAWSXP, n);
-    preserve() ;
+    SEXP m_sexp = Rf_allocVector(RAWSXP, n);
     copy( v.begin(), v.end(), RAW(m_sexp) ) ;
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
-RObject::RObject(const std::set<std::string> & v) {
+RObject wrap(const std::set<std::string> & v){
     logTxt("RObject from set<string>\n");
     int n = v.size();
-    m_sexp = Rf_allocVector(STRSXP, n);
-    preserve() ;
+    SEXP m_sexp = Rf_allocVector(STRSXP, n);
     int i=0;
     std::set<std::string>::iterator it = v.begin(); 
     while( i<n ){
@@ -138,11 +170,15 @@
     	i++ ;
     	it++; 
     }
+    RObject o(m_sexp) ;
+    o.preserve() ;
+    UNPROTECT(1) ;
+    return o ;
 }
 
 RObject::~RObject() {
+	logTxt("~RObject");
 	release() ;
-    logTxt("~RObject");
 }
 
 double RObject::asDouble() const {

Modified: pkg/src/Rcpp/RObject.h
===================================================================
--- pkg/src/Rcpp/RObject.h	2010-01-01 07:01:02 UTC (rev 250)
+++ pkg/src/Rcpp/RObject.h	2010-01-01 08:25:55 UTC (rev 251)
@@ -34,7 +34,9 @@
      * wraps a SEXP. The SEXP is not automatically 
      * protected from garbage collection because it might be 
      * protected from elsewhere (e.g. if it comes from the 
-     * R side). See protect and release for ways to protect
+     * R side). 
+     * 
+     * See preserve and release for ways to protect
      * the SEXP from garbage collection, and release to 
      * remove the protection
      */
@@ -42,29 +44,11 @@
     
     /**
      * if this object is protected rom R's GC, then it is released
-     * and become subject to garbage collection. See protect 
+     * and become subject to garbage collection. See preserve 
      * and release member functions.
      */
     ~RObject() ;
-    
-    RObject(const double & v);
-    RObject(const int & v);
-    RObject(const Rbyte & v);
-    RObject(const std::string & v);
-    RObject(const bool & v);
-    
-    RObject(const std::vector<int> & v);
-    RObject(const std::vector<double> & v);
-    RObject(const std::vector<std::string> & v);
-    RObject(const std::vector<Rbyte> & v);
-    RObject(const std::vector<bool> & v);
-    
-    RObject(const std::set<int> & v);
-    RObject(const std::set<double> & v);
-    RObject(const std::set<std::string> & v);
-    RObject(const std::set<Rbyte> & v);
-    
-    
+   
     /* we don't provide implicit converters because 
        of Item 5 in More Effective C++ */
     bool                     asBool() const;
@@ -175,6 +159,27 @@
     
 };
 
+// factories
+RObject wrap(SEXP m_sexp) ;
+
+RObject wrap(const bool & v);
+RObject wrap(const double & v);
+RObject wrap(const int & v);
+RObject wrap(const Rbyte & v);
+RObject wrap(const std::string & v);
+
+RObject wrap(const std::vector<int> & v);
+RObject wrap(const std::vector<double> & v);
+RObject wrap(const std::vector<std::string> & v);
+RObject wrap(const std::vector<Rbyte> & v);
+RObject wrap(const std::vector<bool> & v);
+
+RObject wrap(const std::set<int> & v);
+RObject wrap(const std::set<double> & v);
+RObject wrap(const std::set<std::string> & v);
+RObject wrap(const std::set<Rbyte> & v);
+
+
 } // namespace Rcpp
 
 // to provide some backwards compatibility with Rcpp 0.7.0 which has RcppSexp

_______________________________________________
Rcpp-commits mailing list
Rcpp-commits at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-commits


More information about the Rcpp-devel mailing list