[Rcpp-commits] r3917 - in pkg/Rcpp: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 8 09:14:04 CET 2012


Author: romain
Date: 2012-11-08 09:14:04 +0100 (Thu, 08 Nov 2012)
New Revision: 3917

Added:
   pkg/Rcpp/man/cppEval.Rd
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Attributes.R
Log:
added cppEval

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-08 07:54:28 UTC (rev 3916)
+++ pkg/Rcpp/ChangeLog	2012-11-08 08:14:04 UTC (rev 3917)
@@ -3,6 +3,8 @@
         * R/Module.R: Module functions taking no arguments don't get the ellipsis
         anymore in their formals
         * src/Module.cpp: passing up the number of arguments of the function
+        * R/Attributes.R: added cppEval
+        * man/cppEval.Rd: documentation for cppeval
         
 2012-11-07  JJ Allaire <jj at rstudio.org>
 

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2012-11-08 07:54:28 UTC (rev 3916)
+++ pkg/Rcpp/NAMESPACE	2012-11-08 08:14:04 UTC (rev 3917)
@@ -16,7 +16,7 @@
 
 export( 
     Module, Rcpp.package.skeleton, populate, loadRcppModules, setRcppClass,
-       loadModule, cppFunction, sourceCpp, compileAttributes
+       loadModule, cppFunction, cppEval, sourceCpp, compileAttributes
 )
 
 exportClass(RcppClass)

Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R	2012-11-08 07:54:28 UTC (rev 3916)
+++ pkg/Rcpp/R/Attributes.R	2012-11-08 08:14:04 UTC (rev 3917)
@@ -196,6 +196,21 @@
     }
 }
 
+# Evaluate a simple c++ expression
+cppEval <- function( code, 
+                     depends = character(), 
+                     includes = character(), 
+                     showOutput = verbose, 
+                     verbose = getOption( "verbose" ) ){
+ 
+                         
+    code <- sprintf( "SEXP get_value(){ return wrap( %s ) ; }", code )
+    env <- new.env()
+    cppFunction( code, depends = depends, includes = includes, env = env, showOutput = showOutput )
+    fun <- env[["get_value"]]
+    fun()
+}
+
 # Scan the source files within a package for attributes and generate code
 # based on the attributes. 
 compileAttributes <- function(pkgdir = ".", verbose = getOption("verbose")) {

Added: pkg/Rcpp/man/cppEval.Rd
===================================================================
--- pkg/Rcpp/man/cppEval.Rd	                        (rev 0)
+++ pkg/Rcpp/man/cppEval.Rd	2012-11-08 08:14:04 UTC (rev 3917)
@@ -0,0 +1,47 @@
+\name{cppEval}
+\alias{cppEval}
+\title{
+Evaluate a C++ expression
+}
+\description{
+Evaluates a C++ expression. This creates a C++ function using 
+\code{\link{cppFunction}} and call it to get the result. 
+}
+\usage{
+cppEval(code, depends = character(), includes = character(), 
+    showOutput = verbose, verbose = getOption("verbose") )
+}
+\arguments{
+  \item{code}{
+C++ expression to evaluate
+}
+  \item{depends}{
+see \code{\link{cppFunction}}
+}
+  \item{includes}{
+see \code{\link{cppFunction}}
+}
+  \item{showOutput}{
+see \code{\link{cppFunction}}
+}
+  \item{verbose}{
+see \code{\link{cppFunction}}
+}
+}
+\note{
+    The result type of the C++ expression must be compatible with wrap.     
+}
+\value{
+    The result of the evaluated C++ expression. 
+}
+\seealso{
+\code{\link{sourceCpp}} and \code{\link{cppFunction}}
+}
+\examples{
+\dontrun{
+
+cppEval( "__cplusplus" )
+cppEval( "std::numeric_limits<double>::max()" )
+    
+}
+}



More information about the Rcpp-commits mailing list