[Rcpp-commits] r4008 - in pkg/Rcpp: . R inst inst/skeleton man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Nov 21 14:34:00 CET 2012


Author: jjallaire
Date: 2012-11-21 14:34:00 +0100 (Wed, 21 Nov 2012)
New Revision: 4008

Added:
   pkg/Rcpp/inst/skeleton/rcpp_hello_world_attributes.cpp
Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/R/Rcpp.package.skeleton.R
   pkg/Rcpp/TODO
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/man/Rcpp.package.skeleton.Rd
Log:
add 'attributes' and 'cpp_files' parameters to Rcpp.pacakge.skeleton

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-11-21 13:04:14 UTC (rev 4007)
+++ pkg/Rcpp/ChangeLog	2012-11-21 13:34:00 UTC (rev 4008)
@@ -1,3 +1,11 @@
+2012-11-21  JJ Allaire <jj at rstudio.org>
+
+        * R/Rcpp.package.skeleton.R: add 'attributes' and 'cpp_files'
+        parameters to Rcpp.pacakge.skeleton
+        * inst/skeleton/rcpp_hello_world_attributes.cpp: version of hello world
+        that uses attributes
+        * man/Rcpp.package.skeleton.Rd: documentation updates
+
 2012-11-21  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/Misc/piBySimulation.r: New simple example using Rcpp

Modified: pkg/Rcpp/R/Rcpp.package.skeleton.R
===================================================================
--- pkg/Rcpp/R/Rcpp.package.skeleton.R	2012-11-21 13:04:14 UTC (rev 4007)
+++ pkg/Rcpp/R/Rcpp.package.skeleton.R	2012-11-21 13:34:00 UTC (rev 4008)
@@ -20,14 +20,18 @@
 Rcpp.package.skeleton <- function(
 	name = "anRpackage", list = character(), environment = .GlobalEnv,
 	path = ".", force = FALSE, namespace = TRUE,
-	code_files = character(),
+	code_files = character(), cpp_files = character(),
 	example_code = TRUE,
+	attributes = FALSE,
 	module = FALSE,
 	author = "Who wrote it",
 	maintainer = if(missing( author)) "Who to complain to" else author,
 	email = "yourfault at somewhere.net",
 	license = "What Licence is it under ?"
 	){
+	
+	if (!is.character(cpp_files)) 
+		stop("'cpp_files' must be a character vector")
 
 	env <- parent.frame(1)
 
@@ -129,21 +133,37 @@
 		file.copy( file.path( skeleton, "Makevars.win" ), Makevars.win )
 		message( " >> added Makevars.win file with Rcpp settings" )
 	}
-
+	
+	if ( length(cpp_files) > 0L ) {
+		for (file in cpp_files) {
+			file.copy(file, src)
+			message( " >> copied ", file, " to src directory" )
+		}
+		compileAttributes(root)
+	}
+	
 	if( example_code ){
-		header <- readLines( file.path( skeleton, "rcpp_hello_world.h" ) )
-		header <- gsub( "@PKG@", name, header, fixed = TRUE )
-		writeLines( header , file.path( src, "rcpp_hello_world.h" ) )
-		message( " >> added example header file using Rcpp classes")
-
-		file.copy( file.path( skeleton, "rcpp_hello_world.cpp" ), src )
-		message( " >> added example src file using Rcpp classes")
-
-		rcode <- readLines( file.path( skeleton, "rcpp_hello_world.R" ) )
-		rcode <- gsub( "@PKG@", name, rcode, fixed = TRUE )
-		writeLines( rcode , file.path( root, "R", "rcpp_hello_world.R" ) )
-		message( " >> added example R file calling the C++ example")
-
+		if ( isTRUE( attributes ) ) {
+			file.copy( file.path( skeleton, "rcpp_hello_world_attributes.cpp" ), 
+								 file.path( src, "rcpp_hello_world.cpp" ) )
+			message( " >> added example src file using Rcpp attributes")
+			compileAttributes(root)
+			message( " >> compiled Rcpp attributes")
+		} else {
+			header <- readLines( file.path( skeleton, "rcpp_hello_world.h" ) )
+			header <- gsub( "@PKG@", name, header, fixed = TRUE )
+			writeLines( header , file.path( src, "rcpp_hello_world.h" ) )
+			message( " >> added example header file using Rcpp classes")
+			
+			file.copy( file.path( skeleton, "rcpp_hello_world.cpp" ), src )
+			message( " >> added example src file using Rcpp classes")
+			
+			rcode <- readLines( file.path( skeleton, "rcpp_hello_world.R" ) )
+			rcode <- gsub( "@PKG@", name, rcode, fixed = TRUE )
+			writeLines( rcode , file.path( root, "R", "rcpp_hello_world.R" ) )
+			message( " >> added example R file calling the C++ example")
+		}
+		
 		hello.Rd <- file.path( root, "man", "rcpp_hello_world.Rd")
 		unlink( hello.Rd )
 		file.copy(

Modified: pkg/Rcpp/TODO
===================================================================
--- pkg/Rcpp/TODO	2012-11-21 13:04:14 UTC (rev 4007)
+++ pkg/Rcpp/TODO	2012-11-21 13:34:00 UTC (rev 4008)
@@ -125,15 +125,11 @@
     
     o   Proactively detect types that can't be handled by as/wrap and print
         a clearer error message
-    
-    o   Enhance Rcpp.package.skeleton to: optionally generate hello_world
-        using attributes and handle existing source files with Rcpp::depends
-        (use inline plugin to get the right Makevars, etc.)
-    
+     
     o   Add unit tests 
 
-    o   Typechecking on CppFunction calls so that seg-faults don't occur
-        when passing incorrect types
+    o   Seg-fault occurs whenever exceptions (including as/wrap incorrect
+        type errors) occur within a module exported function
 
     o   Add docstring parameter to Rcpp::export attribute
 

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2012-11-21 13:04:14 UTC (rev 4007)
+++ pkg/Rcpp/inst/NEWS.Rd	2012-11-21 13:34:00 UTC (rev 4008)
@@ -21,11 +21,20 @@
         \item Changes in Rcpp attributes: 
         \itemize{
             \item Ability to embed R code chunks (via specially formatted
-            block comments) in C++ source files
-            \item Allow specification of argument defaults for exported functions 
+            block comments) in C++ source files.
+            \item Allow specification of argument defaults for exported functions. 
             \item New scheme for more flexible mixing of generated and user composed
-            C++ headers
-            \item Print warning if no export attributes are found in source file
+            C++ headers.
+            \item Additions to \code{Rcpp.package.skeleton}:
+            \itemize{
+            	\item \code{attributes} parameter to generate a version of 
+            	\code{rcpp_hello_world} that uses \code{Rcpp::export}.
+            	\item \code{cpp_files} parameter to provide a list of C++
+            	files to include the in the \code{src} directory of the package.
+            }
+            \item Print warning if no export attributes are found in source file.
+            \item Updated vignette with additional documentation on exposing
+            C++ interfaces from packages.
         }
         \item Changes in R code :
         \itemize{

Added: pkg/Rcpp/inst/skeleton/rcpp_hello_world_attributes.cpp
===================================================================
--- pkg/Rcpp/inst/skeleton/rcpp_hello_world_attributes.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/skeleton/rcpp_hello_world_attributes.cpp	2012-11-21 13:34:00 UTC (rev 4008)
@@ -0,0 +1,13 @@
+
+#include <Rcpp.h>
+using namespace Rcpp;
+
+// [[Rcpp::export]]
+List rcpp_hello_world() {
+   
+    CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
+    NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
+    List z            = List::create( x, y ) ;
+    
+    return z ;
+}

Modified: pkg/Rcpp/man/Rcpp.package.skeleton.Rd
===================================================================
--- pkg/Rcpp/man/Rcpp.package.skeleton.Rd	2012-11-21 13:04:14 UTC (rev 4007)
+++ pkg/Rcpp/man/Rcpp.package.skeleton.Rd	2012-11-21 13:34:00 UTC (rev 4008)
@@ -13,8 +13,8 @@
 \usage{
 Rcpp.package.skeleton(name = "anRpackage", list = character(), 
 	environment = .GlobalEnv, path = ".", force = FALSE, 
-	namespace = TRUE, code_files = character(), 
-	example_code = TRUE, module = FALSE, 
+	namespace = TRUE, code_files = character(), cpp_files = character(),
+	example_code = TRUE, attributes = FALSE, module = FALSE, 
 	author = "Who wrote it", 
 	maintainer = if(missing( author)) "Who to complain to" else author, 
 	email = "yourfault at somewhere.net", 
@@ -29,7 +29,9 @@
 	\item{force}{See \link[utils]{package.skeleton}}
 	\item{namespace}{See \link[utils]{package.skeleton}}
 	\item{code_files}{See \link[utils]{package.skeleton}}
+	\item{cpp_files}{A character vector with the paths to C++ source files to add to the package. }
 	\item{example_code}{If TRUE, example c++ code using Rcpp is added to the package. }
+	\item{attributes}{If TRUE, example code makes use of Rcpp attributes.}
 	\item{module}{If TRUE, an example \code{\link{Module}} is added to the skeleton. }
 	\item{author}{Author of the package.}
 	\item{maintainer}{Maintainer of the package.}
@@ -49,6 +51,9 @@
 	a \samp{Makevars} file is added setting the environment variables
 	\samp{PKG_LIBS} to accomodate the necessary flags to link with the Rcpp library. 
 	
+	If \code{cpp_files} are provided then they will be copied to the \samp{src}
+	directory.
+	
 	If the \code{example_code} argument is set to \code{TRUE}, 
 	example files \samp{rcpp_hello_world.h} and \samp{rcpp_hello_world.cpp}
 	are also created in the \samp{src}. An R file \samp{rcpp_hello_world.R} is 
@@ -57,6 +62,10 @@
 	defined in the C++ file. These files are given as an example and should 
 	eventually by removed from the generated package.
 	
+	If the \code{attributes} argument is \code{TRUE}, then rather than generate
+	the example files as described above, a single \samp{rcpp_hello_world.cpp}
+	file is created in the \samp{src} directory and it's attributes are compiled.
+	
 	If the \code{module} argument is \code{TRUE}, a sample Rcpp module will 
 	be generated as well. 
 }
@@ -78,6 +87,9 @@
 # simple package
 Rcpp.package.skeleton( "foobar" )
 
+# package using attributes
+Rcpp.package.skeleton( "foobar", attributes = TRUE )
+
 # package with a module
 Rcpp.package.skeleton( "testmod", module = TRUE )
 



More information about the Rcpp-commits mailing list