[Rcpp-commits] r4516 - in pkg/RcppExamples: R man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 18 22:18:46 CEST 2013


Author: romain
Date: 2013-09-18 22:18:46 +0200 (Wed, 18 Sep 2013)
New Revision: 4516

Added:
   pkg/RcppExamples/man/RcppDateExample.Rd
   pkg/RcppExamples/man/RcppMatrixExample.Rd
   pkg/RcppExamples/man/RcppStringVectorExample.Rd
Modified:
   pkg/RcppExamples/R/RcppExports.R
   pkg/RcppExamples/R/RcppMatrixExample.R
   pkg/RcppExamples/R/RcppStringVectorExample.R
   pkg/RcppExamples/src/MatrixExample.cpp
   pkg/RcppExamples/src/RcppExports.cpp
   pkg/RcppExamples/src/StringVectorExample.cpp
Log:
second part of the 'flood', passing R CMD check

Modified: pkg/RcppExamples/R/RcppExports.R
===================================================================
--- pkg/RcppExamples/R/RcppExports.R	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/R/RcppExports.R	2013-09-18 20:18:46 UTC (rev 4516)
@@ -13,8 +13,8 @@
     .Call('RcppExamples_ListExamples', PACKAGE = 'RcppExamples', rparam)
 }
 
-newRcppMatrixExample <- function(orig) {
-    .Call('RcppExamples_newRcppMatrixExample', PACKAGE = 'RcppExamples', orig)
+MatrixExample <- function(orig) {
+    .Call('RcppExamples_MatrixExample', PACKAGE = 'RcppExamples', orig)
 }
 
 NumericVectorExample <- function(orig) {
@@ -25,3 +25,7 @@
     .Call('RcppExamples_RcppRNGs', PACKAGE = 'RcppExamples', n)
 }
 
+StringVectorExample <- function(orig) {
+    .Call('RcppExamples_StringVectorExample', PACKAGE = 'RcppExamples', orig)
+}
+

Modified: pkg/RcppExamples/R/RcppMatrixExample.R
===================================================================
--- pkg/RcppExamples/R/RcppMatrixExample.R	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/R/RcppMatrixExample.R	2013-09-18 20:18:46 UTC (rev 4516)
@@ -21,6 +21,6 @@
 
 RcppMatrixExample <- function(mat=matrix(seq(1,9)^2, ncol=3)) {
     ## Make the call...
-    val <- .Call("newRcppMatrixExample", mat, PACKAGE="RcppExamples")
+    val <- MatrixExample( mat )
     val
 }

Modified: pkg/RcppExamples/R/RcppStringVectorExample.R
===================================================================
--- pkg/RcppExamples/R/RcppStringVectorExample.R	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/R/RcppStringVectorExample.R	2013-09-18 20:18:46 UTC (rev 4516)
@@ -21,6 +21,6 @@
 
 RcppStringVectorExample <- function(vec=c("Tick", "Tack", "Tock")) {
     ## Make the call...
-    val <- .Call("newRcppStringVectorExample", vec, PACKAGE="RcppExamples")
+    val <- StringVectorExample( vec )
     val
 }

Added: pkg/RcppExamples/man/RcppDateExample.Rd
===================================================================
--- pkg/RcppExamples/man/RcppDateExample.Rd	                        (rev 0)
+++ pkg/RcppExamples/man/RcppDateExample.Rd	2013-09-18 20:18:46 UTC (rev 4516)
@@ -0,0 +1,62 @@
+\name{RcppDateExample}
+\alias{RcppDateExample}
+\title{C++ classes for interfacing date and datetime R objects}
+\description{
+    Rcpp has the classes \code{Rcpp::Date}, \code{Rcpp::Datetime}, 
+    \code{Rcpp::DateVector} and \code{Rcpp::DatetimeVector}.
+}
+\details{
+
+    In the \code{C++} code for the \code{RcppDateExample.cpp} file: 
+    
+    \preformatted{%
+        // [[Rcpp::export]]
+        List DateExample(DateVector dv, DatetimeVector dtv) {
+            Function formatDate("format.Date");
+            Function formatDatetime("format.POSIXct");
+            
+            Rprintf("\nIn C++, seeing the following date value\n");
+            for (int i=0; i<dv.size(); i++) {
+                Rcout << as<std::string>(formatDate(wrap(dv[i]))) << std::endl;
+                dv[i] = dv[i] + 7;		// shift a week
+            }
+            Rprintf("\nIn C++, seeing the following datetime value\n");
+            for (int i=0; i<dtv.size(); i++) {
+                Rcout << as<std::string>(formatDatetime(wrap(dtv[i]))) << std::endl;
+                dtv[i] = dtv[i] + 0.250;    // shift 250 millisec
+            }
+            
+            // Build result set to be returned as a list to R.
+            List result = List::create(
+                Named("date",   dv),
+                Named("datetime", dtv)
+                );
+            
+            return result ;
+        }
+    
+    }
+}
+\references{
+  \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+  RcppTemplate) during 2005 and 2006.  Dirk Eddelbuettel made some
+  additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+  Francois have been extending Rcpp since 2009.
+}
+\examples{
+
+# set up date and datetime vectors
+dvec <- Sys.Date() + -2:2
+dtvec <- Sys.time() + (-2:2)*0.5
+
+# call the underlying  C++ function
+result <- RcppDateExample(dvec, dtvec)
+
+# inspect returned object
+result
+}
+\keyword{programming}
+\keyword{interface}
+

Added: pkg/RcppExamples/man/RcppMatrixExample.Rd
===================================================================
--- pkg/RcppExamples/man/RcppMatrixExample.Rd	                        (rev 0)
+++ pkg/RcppExamples/man/RcppMatrixExample.Rd	2013-09-18 20:18:46 UTC (rev 4516)
@@ -0,0 +1,55 @@
+\name{RcppMatrixExample}
+\alias{RcppMatrixExample}
+\title{Example of using Rcpp NumericMatrix}
+\description{
+    The \code{NumericMatrix} class represents numeric matrices
+}
+\details{
+
+    The \code{C++} code presented in the \code{MatrixExample.cpp} file: 
+    
+    \preformatted{%
+        #include <Rcpp.h>
+        #include <cmath>
+        
+        /* suncc needs help to disambiguate between sqrt( float ) and sqrt(double) */
+        inline static double sqrt_double( double x ){ return ::sqrt( x ) ; }
+        
+        using namespace Rcpp; 
+        
+        // [[Rcpp::export]]
+        List MatrixExample(NumericMatrix orig) {
+            NumericMatrix mat(orig.nrow(), orig.ncol());	
+        
+            // we could query size via
+            //   int n = mat.nrow(), k=mat.ncol();
+            // and loop over the elements, but using the STL is so much nicer
+            // so we use a STL transform() algorithm on each element
+            std::transform(orig.begin(), orig.end(), mat.begin(), sqrt_double );
+        
+            List result = List::create(
+                Named( "result" ) = mat, 
+                Named( "original" ) = orig
+            );
+            return result ;
+        }
+    
+    }
+}
+\references{
+  \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+  RcppTemplate) during 2005 and 2006.  Dirk Eddelbuettel made some
+  additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+  Francois have been extending Rcpp since 2009.
+}
+\examples{
+
+M <- matrix( (1:16)^2, 4 )
+RcppMatrixExample( M )
+
+}
+\keyword{programming}
+\keyword{interface}
+

Added: pkg/RcppExamples/man/RcppStringVectorExample.Rd
===================================================================
--- pkg/RcppExamples/man/RcppStringVectorExample.Rd	                        (rev 0)
+++ pkg/RcppExamples/man/RcppStringVectorExample.Rd	2013-09-18 20:18:46 UTC (rev 4516)
@@ -0,0 +1,46 @@
+\name{RcppStringVectorExample}
+\alias{RcppStringVectorExample}
+\title{Example of using Rcpp StringVector (aka CharacterVector) }
+\description{
+    The \code{StringVector} (aka \code{CharacterVector}
+    class represents character vectors. 
+}
+\details{
+
+    The \code{C++} code presented in the \code{StringVectorExample.cpp} file: 
+    
+    \preformatted{%
+        #include <Rcpp.h>
+        using namespace Rcpp ;
+        
+        // [[Rcpp::export]]
+        List StringVectorExample(StringVector orig) {
+            StringVector vec(orig.size());	
+        
+            std::transform(orig.begin(), orig.end(), vec.begin(), 
+        		   make_string_transformer(tolower));
+        
+            List result = List::create(
+                Named( "result" )   = vec,
+                Named( "original" ) = orig
+            );
+            return result ;
+        }
+
+    }
+}
+\references{
+  \emph{Writing R Extensions}, available at \url{http:www.r-project.org}.
+}
+\author{Dominick Samperi wrote the initial versions of Rcpp (and
+  RcppTemplate) during 2005 and 2006.  Dirk Eddelbuettel made some
+  additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain
+  Francois have been extending Rcpp since 2009.
+}
+\examples{
+
+RcppStringVectorExample( c("Tick", "Tack", "Tock") )
+
+}
+\keyword{programming}
+\keyword{interface}

Modified: pkg/RcppExamples/src/MatrixExample.cpp
===================================================================
--- pkg/RcppExamples/src/MatrixExample.cpp	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/src/MatrixExample.cpp	2013-09-18 20:18:46 UTC (rev 4516)
@@ -28,7 +28,7 @@
 using namespace Rcpp; 
 
 // [[Rcpp::export]]
-List newRcppMatrixExample(NumericMatrix orig) {
+List MatrixExample(NumericMatrix orig) {
     NumericMatrix mat(orig.nrow(), orig.ncol());	
 
     // we could query size via
@@ -44,5 +44,3 @@
     return result ;
 }
 
-
-

Modified: pkg/RcppExamples/src/RcppExports.cpp
===================================================================
--- pkg/RcppExamples/src/RcppExports.cpp	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/src/RcppExports.cpp	2013-09-18 20:18:46 UTC (rev 4516)
@@ -51,15 +51,15 @@
     return __sexp_result;
 END_RCPP
 }
-// newRcppMatrixExample
-List newRcppMatrixExample(NumericMatrix orig);
-RcppExport SEXP RcppExamples_newRcppMatrixExample(SEXP origSEXP) {
+// MatrixExample
+List MatrixExample(NumericMatrix orig);
+RcppExport SEXP RcppExamples_MatrixExample(SEXP origSEXP) {
 BEGIN_RCPP
     SEXP __sexp_result;
     {
         Rcpp::RNGScope __rngScope;
         Rcpp::traits::input_parameter< NumericMatrix >::type orig(origSEXP );
-        List __result = newRcppMatrixExample(orig);
+        List __result = MatrixExample(orig);
         PROTECT(__sexp_result = Rcpp::wrap(__result));
     }
     UNPROTECT(1);
@@ -96,3 +96,18 @@
     return __sexp_result;
 END_RCPP
 }
+// StringVectorExample
+List StringVectorExample(StringVector orig);
+RcppExport SEXP RcppExamples_StringVectorExample(SEXP origSEXP) {
+BEGIN_RCPP
+    SEXP __sexp_result;
+    {
+        Rcpp::RNGScope __rngScope;
+        Rcpp::traits::input_parameter< StringVector >::type orig(origSEXP );
+        List __result = StringVectorExample(orig);
+        PROTECT(__sexp_result = Rcpp::wrap(__result));
+    }
+    UNPROTECT(1);
+    return __sexp_result;
+END_RCPP
+}

Modified: pkg/RcppExamples/src/StringVectorExample.cpp
===================================================================
--- pkg/RcppExamples/src/StringVectorExample.cpp	2013-09-18 15:59:15 UTC (rev 4515)
+++ pkg/RcppExamples/src/StringVectorExample.cpp	2013-09-18 20:18:46 UTC (rev 4516)
@@ -20,21 +20,19 @@
 // along with RcppExamples.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <Rcpp.h>
+using namespace Rcpp ;
 
-RcppExport SEXP newRcppStringVectorExample(SEXP strvec) {
-BEGIN_RCPP
+// [[Rcpp::export]]
+List StringVectorExample(StringVector orig) {
+    StringVector vec(orig.size());	
 
-    Rcpp::StringVector orig(strvec);		// creates Rcpp string vector from SEXP
-    Rcpp::StringVector vec(orig.size());	
-
     std::transform(orig.begin(), orig.end(), vec.begin(), 
-		   Rcpp::make_string_transformer(tolower));
+		   make_string_transformer(tolower));
 
-    return Rcpp::List::create(Rcpp::Named( "result" )   = vec,
-			      Rcpp::Named( "original" ) = orig);
-
-END_RCPP
+    List result = List::create(
+        Named( "result" )   = vec,
+        Named( "original" ) = orig
+    );
+    return result ;
 }
 
-
-



More information about the Rcpp-commits mailing list