[Rcpp-commits] r380 - in pkg: R inst inst/skeleton

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 16 10:23:20 CET 2010


Author: romain
Date: 2010-01-16 10:23:19 +0100 (Sat, 16 Jan 2010)
New Revision: 380

Added:
   pkg/inst/skeleton/
   pkg/inst/skeleton/Makevars
   pkg/inst/skeleton/rcpp_hello_world.R
   pkg/inst/skeleton/rcpp_hello_world.cpp
   pkg/inst/skeleton/rcpp_hello_world.h
Modified:
   pkg/R/Rcpp.package.skeleton.R
   pkg/inst/ChangeLog
Log:
added c++ code example in skeleton, use the Makevars hack

Modified: pkg/R/Rcpp.package.skeleton.R
===================================================================
--- pkg/R/Rcpp.package.skeleton.R	2010-01-15 15:01:18 UTC (rev 379)
+++ pkg/R/Rcpp.package.skeleton.R	2010-01-16 09:23:19 UTC (rev 380)
@@ -17,7 +17,8 @@
 
 Rcpp.package.skeleton <- function(
 	name = "anRpackage", list = character(), environment = .GlobalEnv,
-	path = ".", force = FALSE, namespace = TRUE, code_files = character() ){
+	path = ".", force = FALSE, namespace = TRUE, 
+	code_files = character() ){
 	
 	# first let the traditional version do its business
 	call <- match.call()
@@ -60,15 +61,26 @@
 	if( !file.exists( src )){
 		dir.create( src )
 	}
+	skeleton <- system.file( "skeleton", package = "Rcpp" )
 	Makevars <- file.path( src, "Makevars" )
 	if( !file.exists( Makevars ) ){
-		writeLines(  c( 
-		"PKG_CXXFLAGS=`Rscript -e \"Rcpp:::CxxFlags()\" `" , 
-		"PKG_LIBS = `Rscript -e \"Rcpp:::LdFlasgs()\" `"  ), 
-		, con = Makevars )
+		file.copy( file.path( skeleton, "Makevars" ), Makevars )
 		message( " >> added Makevars file with Rcpp settings" )
 	}
 	
+	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")
+	
 	invisible( NULL )
 }
 

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-01-15 15:01:18 UTC (rev 379)
+++ pkg/inst/ChangeLog	2010-01-16 09:23:19 UTC (rev 380)
@@ -1,3 +1,12 @@
+2010-01-16  Romain Francois <francoisromain at free.fr>
+
+	* R/Rcpp.package.skeleton: now generating example C++ and R
+	code that uses Rcpp, also the generated Makevars contains
+	a hack so that the generated package can pass check (after
+	edition of Rd files, NAMESPACE, etc ...)
+	* inst/skeleton: added example code used by the skeleton 
+	generator
+
 2010-01-15  Romain Francois <francoisromain at free.fr>
 
 	* src/Rcpp/NumericVector.h: cache the start of the array to

Added: pkg/inst/skeleton/Makevars
===================================================================
--- pkg/inst/skeleton/Makevars	                        (rev 0)
+++ pkg/inst/skeleton/Makevars	2010-01-16 09:23:19 UTC (rev 380)
@@ -0,0 +1,10 @@
+PKG_CXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"` -I.
+PKG_LIBS = `Rscript -e "Rcpp:::LdFlags()" `
+
+all: $(SHLIB) hack
+
+# this hack is there to prevent R CMD check from rejecting 
+# our CxxFlags
+hack:
+	mkdir tmp; cp $(SHLIB) tmp/ ; rm -fr tmp
+

Added: pkg/inst/skeleton/rcpp_hello_world.R
===================================================================
--- pkg/inst/skeleton/rcpp_hello_world.R	                        (rev 0)
+++ pkg/inst/skeleton/rcpp_hello_world.R	2010-01-16 09:23:19 UTC (rev 380)
@@ -0,0 +1,5 @@
+
+rcpp_hello_world <- function(){
+	.Call( "rcpp_hello_world", PACKAGE = "@PKG@" )
+}
+

Added: pkg/inst/skeleton/rcpp_hello_world.cpp
===================================================================
--- pkg/inst/skeleton/rcpp_hello_world.cpp	                        (rev 0)
+++ pkg/inst/skeleton/rcpp_hello_world.cpp	2010-01-16 09:23:19 UTC (rev 380)
@@ -0,0 +1,19 @@
+#include <rcpp_hello_world.h>
+
+SEXP rcpp_hello_world(){
+	using namespace Rcpp ;
+	
+	CharacterVector x(2) ;
+	x[0] = "foo" ; 
+	x[1] = "bar" ;
+	
+	NumericVector y(2) ;
+	y[0] = 0.0 ;
+	y[1] = 1.0 ;
+	
+	List z(2) ; 
+	z[0] = x ; 
+	z[1] = y ;
+	
+	return z ;
+}

Added: pkg/inst/skeleton/rcpp_hello_world.h
===================================================================
--- pkg/inst/skeleton/rcpp_hello_world.h	                        (rev 0)
+++ pkg/inst/skeleton/rcpp_hello_world.h	2010-01-16 09:23:19 UTC (rev 380)
@@ -0,0 +1,8 @@
+#ifndef _ at PKG@_RCPP_HELLO_WORLD_H
+#define _ at PKG@_RCPP_HELLO_WORLD_H
+
+#include <Rcpp.h>
+
+RcppExport SEXP rcpp_hello_world() ;
+
+#endif



More information about the Rcpp-commits mailing list