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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 12 22:16:24 CET 2013


Author: jjallaire
Date: 2013-01-12 22:16:24 +0100 (Sat, 12 Jan 2013)
New Revision: 4193

Added:
   pkg/Rcpp/man/pluginsAttribute.Rd
   pkg/Rcpp/man/registerPlugin.Rd
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Attributes.R
   pkg/Rcpp/man/cppFunction.Rd
Log:
add registerPlugin function; add plugins parameter to cppFunction

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-01-12 19:39:40 UTC (rev 4192)
+++ pkg/Rcpp/ChangeLog	2013-01-12 21:16:24 UTC (rev 4193)
@@ -1,3 +1,13 @@
+2014-01-12  JJ Allaire <jj at rstudio.org>
+
+        * DESCRIPTION: bump version to 0.10.2.2
+        * NAMESPACE: add registerPlugin function
+        * R/Attributes.R: add registerPlugin function; add plugins parameter
+        to cppFunction
+        * man/cppFunction.Rd: documentation updates
+        * man/pluginsAttribute.Rd: documentation updates
+        * man/registerPlugin: documentation updates
+
 2014-01-11  JJ Allaire <jj at rstudio.org>
 
         * R/Attributes.R: initial support for Rcpp::plugins attribute; add

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2013-01-12 19:39:40 UTC (rev 4192)
+++ pkg/Rcpp/DESCRIPTION	2013-01-12 21:16:24 UTC (rev 4193)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Seamless R and C++ Integration
-Version: 0.10.2.1
+Version: 0.10.2.2
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Douglas Bates, John Chambers and JJ Allaire

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2013-01-12 19:39:40 UTC (rev 4192)
+++ pkg/Rcpp/NAMESPACE	2013-01-12 21:16:24 UTC (rev 4193)
@@ -15,7 +15,7 @@
 
 export( 
     Module, Rcpp.package.skeleton, populate, loadRcppModules, setRcppClass,
-       loadModule, cppFunction, evalCpp, sourceCpp, compileAttributes
+       loadModule, cppFunction, evalCpp, sourceCpp, compileAttributes, registerPlugin
 )
 
 exportClass(RcppClass)

Modified: pkg/Rcpp/R/Attributes.R
===================================================================
--- pkg/Rcpp/R/Attributes.R	2013-01-12 19:39:40 UTC (rev 4192)
+++ pkg/Rcpp/R/Attributes.R	2013-01-12 21:16:24 UTC (rev 4193)
@@ -161,13 +161,14 @@
 # Define a single C++ function
 cppFunction <- function(code, 
                         depends = character(),
+                        plugins = character(),
                         includes = character(),
                         env = parent.frame(),
                         rebuild = FALSE,
                         showOutput = verbose,
                         verbose = getOption("verbose")) {
     
-    # generate required scaffolding
+    # process depends
     if (!is.null(depends) && length(depends) > 0) {
         depends <- paste(depends, sep=", ")
         scaffolding <- paste("// [[Rcpp::depends(", depends, ")]]", sep="")
@@ -177,6 +178,15 @@
     else {
         scaffolding <- "#include <Rcpp.h>"
     }
+    
+    # process plugins
+    if (!is.null(plugins) && length(plugins) > 0) {
+        plugins <- paste(plugins, sep=", ")
+        pluginsAttrib <- paste("// [[Rcpp::plugins(", plugins, ")]]", sep="")
+        scaffolding <- c(scaffolding, pluginsAttrib)
+    }
+    
+    # remainder of scaffolding
     scaffolding <- c(scaffolding, 
                      "",
                      "using namespace Rcpp;", 
@@ -313,11 +323,20 @@
                     includes, verbose, .Platform))
 }
 
+# setup plugins environment
+.plugins <- new.env()
 
 # built-in C++11 plugin
-cpp11 <- function() list(env = list(PKG_CXXFLAGS ="-std=c++11"))
+.plugins[["cpp11"]] <- function() {
+    list(env = list(PKG_CXXFLAGS ="-std=c++11"))
+}
 
+# register a plugin
+registerPlugin <- function(name, plugin) {
+    .plugins[[name]] <- plugin    
+}
 
+
 # Take an empty function body and connect it to the specified external symbol
 sourceCppFunction <- function(func, isVoid, dll, symbol) {
     
@@ -453,13 +472,12 @@
     
     # process plugins
     for (pluginName in plugins) {
-        plugin <- tryCatch(eval(parse(text=pluginName)), 
-                           error = function(e) NULL)
-        if (!is.function(plugin))
+        plugin <- .plugins[[pluginName]]
+        if (is.null(plugin))
             stop("Inline plugin '", pluginName, "' could not be found.")
         setDependenciesFromPlugin(plugin)
     }
-     
+    
     # if there is no buildEnv from a plugin then use the Rcpp plugin
     if (length(buildEnv) == 0) {
         buildEnv <- Rcpp:::inlineCxxPlugin()$env

Modified: pkg/Rcpp/man/cppFunction.Rd
===================================================================
--- pkg/Rcpp/man/cppFunction.Rd	2013-01-12 19:39:40 UTC (rev 4192)
+++ pkg/Rcpp/man/cppFunction.Rd	2013-01-12 21:16:24 UTC (rev 4193)
@@ -7,8 +7,8 @@
 Dynamically define an R function with C++ source code. Compiles and links a shared library with bindings to the C++ function then defines an R function that uses \code{.Call} to invoke the library.
 }
 \usage{
-cppFunction(code, depends = character(), includes = character(), 
-            env = parent.frame(), rebuild = FALSE, 
+cppFunction(code, depends = character(), plugins = character(),
+            includes = character(), env = parent.frame(), rebuild = FALSE, 
             showOutput = verbose, verbose = getOption("verbose"))
 }
 
@@ -19,6 +19,9 @@
   \item{depends}{
     Character vector of packages that the compilation depends on. Each package listed will first be queried for an \link[inline:plugins]{inline plugin} to determine header files to include. If no plugin is defined for the package then a header file based the package's name (e.g. \code{PkgName.hpp}) will be included.
 }
+  \item{plugins}{
+    Character vector of \link[inline:plugins]{inline plugins} to use for the compliation.
+  }
   \item{includes}{
     Character vector of user includes (inserted after the includes provided by \code{depends}).
 }
@@ -81,5 +84,12 @@
             Named("stderr")       = stderrest
         );
     }')
+    
+cppFunction(plugins=c("cpp11"), '
+    int useCpp11() {
+        auto x = 10;
+        return x;
+    }')
+    
 }
 }

Added: pkg/Rcpp/man/pluginsAttribute.Rd
===================================================================
--- pkg/Rcpp/man/pluginsAttribute.Rd	                        (rev 0)
+++ pkg/Rcpp/man/pluginsAttribute.Rd	2013-01-12 21:16:24 UTC (rev 4193)
@@ -0,0 +1,42 @@
+\name{pluginsAttribute}
+\alias{pluginsAttribute}
+
+\title{Rcpp::plugins Attribute}
+
+\description{
+The \code{Rcpp::plugins} attribute is added to a C++ source file to specify the
+\link[inline:plugins]{inline plugins} that should be used in the compilation.
+\preformatted{
+// [[Rcpp::plugins(plugin1, plugin2)]]
+}
+}
+
+\arguments{
+ \item{\dots}{
+   Plugins to add to the compilation.
+}
+}
+
+\details{
+    Note that plugins must be registered using the \code{\link{registerPlugin}}
+    function. \pkg{Rcpp} also includes a built-in \code{cpp11} plugin that
+    adds the flag required to enable \code{C++11} features in the compiler.
+}
+
+\seealso{
+\code{\link{registerPlugin}}
+}
+
+\examples{
+\dontrun{
+
+// [[Rcpp::plugins(cpp11)]]
+
+// [[Rcpp::export]]
+int useCpp11() {
+    auto x = 10;
+    return x;
+}
+}
+}
+

Added: pkg/Rcpp/man/registerPlugin.Rd
===================================================================
--- pkg/Rcpp/man/registerPlugin.Rd	                        (rev 0)
+++ pkg/Rcpp/man/registerPlugin.Rd	2013-01-12 21:16:24 UTC (rev 4193)
@@ -0,0 +1,27 @@
+\name{registerPlugin}
+\alias{registerPlugin}
+\title{
+Register an inline plugin
+}
+\description{
+Register an \link[inline:plugins]{inline plugin} for use with 
+\code{\link{sourceCpp}} or \code{\link{cppFunction}}. Inline plugins are functions
+that return a list with additional includes, environment variables, and
+other compilation context. 
+}
+\usage{
+registerPlugin(name, plugin)
+}
+\arguments{
+    \item{name}{Name of the inline plugin}
+    \item{plugin}{Inline plugin function}
+}
+\details{
+    Plugins can be added to \code{\link{sourceCpp}} compilations using the
+    \code{\link[=pluginsAttribute]{Rcpp::plugins}} attribute.
+}
+\seealso{
+    \code{\link[=pluginsAttribute]{Rcpp::plugins}}
+}
+
+



More information about the Rcpp-commits mailing list