[Rcpp-commits] r1049 - in pkg/Rcpp: inst/unitTests man src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 15 11:42:49 CEST 2010


Author: romain
Date: 2010-04-15 11:42:48 +0200 (Thu, 15 Apr 2010)
New Revision: 1049

Added:
   pkg/Rcpp/man/cppfunction.Rd
Modified:
   pkg/Rcpp/inst/unitTests/runit.dotCpp.R
   pkg/Rcpp/src/do_dot_cpp.cpp
Log:
added Rd file for cppfunction

Modified: pkg/Rcpp/inst/unitTests/runit.dotCpp.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.dotCpp.R	2010-04-15 08:59:14 UTC (rev 1048)
+++ pkg/Rcpp/inst/unitTests/runit.dotCpp.R	2010-04-15 09:42:48 UTC (rev 1049)
@@ -21,8 +21,8 @@
 	suppressMessages( require( inline ) )
 }
 
-generate.dot.cpp.code <- function(i ){
-	code <- sprintf( '.Cpp( "testfun_%d" %s, PACKAGE = "Rcpp" )', i, 
+generate.dot.cpp.code <- function(i, suffix = "" ){
+	code <- sprintf( '.Cpp( "testfun_%s%d" %s, PACKAGE = "Rcpp" )', suffix, i, 
 		if( i == 0L ) "" else paste( ", ", paste( 0:(i-1), collapse = ", "), sep = "" )
 	)
 	parse( text = code )
@@ -35,3 +35,16 @@
 	}
 }
 
+test.dot.cpp.exceptions <- function(){
+	for( i in 0:65 ){
+		expr <- generate.dot.cpp.code(i, "ex_")
+		error <- tryCatch( {
+			eval(expr)
+			FALSE	
+		}, "std::range_error" = function(e){
+			TRUE
+		} )
+		checkTrue( error, msg = sprintf( ".Cpp (%d arguments) throwing exception", i ) )
+	}
+}
+

Added: pkg/Rcpp/man/cppfunction.Rd
===================================================================
--- pkg/Rcpp/man/cppfunction.Rd	                        (rev 0)
+++ pkg/Rcpp/man/cppfunction.Rd	2010-04-15 09:42:48 UTC (rev 1049)
@@ -0,0 +1,51 @@
+\name{cppfunction}
+\alias{cppfunction}
+\title{
+Functionality to dynamically define R functions
+with inlined c++ code that uses Rcpp classes
+}
+\description{
+\code{cppfunction} is a slightly modified version of \link[inline]{cfunction} 
+}
+\usage{
+cppfunction(sig = character(), body = character(), includes = character(), 
+otherdefs = character(), verbose = FALSE, cppargs = character(), 
+cxxargs = character(), libargs = character(), .Cpp = TRUE, namespace = TRUE)
+}
+\arguments{
+\item{sig}{Signature. See \link[inline]{cfunction}}
+\item{body}{C++ code to inline. See \link[inline]{cfunction}}
+\item{includes}{See \link[inline]{cfunction}}
+\item{otherdefs}{See \link[inline]{cfunction}}
+\item{verbose}{See \link[inline]{cfunction}}
+\item{cppargs}{See \link[inline]{cfunction}}
+\item{cxxargs}{See \link[inline]{cfunction}}
+\item{libargs}{See \link[inline]{cfunction}}
+\item{.Cpp}{If \code{TRUE} (which is the default and is recommended), 
+  	  the call to \link{.Call} is replaced by a call to \link{.Cpp}
+  	  which is identical except that it handles c++ exceptions
+}
+\item{namespace}{If \code{TRUE} the line "using namespace Rcpp; " is added
+to the includes list}
+}
+\details{
+	As opposed to \link[inline]{cfunction}, this function can only code 
+	that is designed to use the \link{.Call} interface, the language is 
+	restricted to C++ and the \code{Rcpp} argument of \link[inline]{cfunction}
+	is set to \code{TRUE}
+}
+\value{
+An R function, similar to the returned value of \link[inline]{cfunction}
+}
+\references{
+Oleg Sklyar, Duncan Murdoch, Mike Smith and Dirk Eddelbuettel (2009).
+  inline: Inline C, C++, Fortran function calls from R. R package
+  version 0.3.4. \url{http://CRAN.R-project.org/package=inline}
+}
+\examples{
+\dontrun{
+fx <- cppfunction( body = "return IntegerVector::create( 1, 2, 3) ;" )
+stopifnot( identical( fx(), 1:3 ) ) 
+}
+}
+\keyword{interface}

Modified: pkg/Rcpp/src/do_dot_cpp.cpp
===================================================================
--- pkg/Rcpp/src/do_dot_cpp.cpp	2010-04-15 08:59:14 UTC (rev 1048)
+++ pkg/Rcpp/src/do_dot_cpp.cpp	2010-04-15 09:42:48 UTC (rev 1049)
@@ -27,7 +27,6 @@
 /* because here we know we are using c++ */
 typedef SEXP (*VarFun)(...);
 #define MAX_ARGS 65
-#define MaxSymbolBytes 1024
 typedef union {void *p; DL_FUNC fn;} fn_ptr;
 
 /* retrieves a function pointer from an external pointer */



More information about the Rcpp-commits mailing list