[Rcpp-commits] r1391 - in pkg/Rcpp: . R inst/doc/Rcpp-modules inst/prompt inst/skeleton man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 1 12:28:09 CEST 2010


Author: romain
Date: 2010-06-01 12:28:09 +0200 (Tue, 01 Jun 2010)
New Revision: 1391

Added:
   pkg/Rcpp/inst/skeleton/rcpp_hello_world.Rd
Modified:
   pkg/Rcpp/NEWS
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/R/Rcpp.package.skeleton.R
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
   pkg/Rcpp/inst/prompt/module.Rd
   pkg/Rcpp/inst/skeleton/yada.Rd
   pkg/Rcpp/inst/skeleton/zzz.R
   pkg/Rcpp/man/Rcpp.package.skeleton.Rd
Log:
some adjustments to Rcpp.package.skeleyon

Modified: pkg/Rcpp/NEWS
===================================================================
--- pkg/Rcpp/NEWS	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/NEWS	2010-06-01 10:28:09 UTC (rev 1391)
@@ -1,7 +1,5 @@
 0.8.1   (under development)
 
-	o	Evaluating a call inside an environment did not work properly
-	
 	o	Rcpp modules. An Rcpp module is a collection of internal (c++)
 	functions and classes that are exposed to R. Inspired from
 	Boost.Python
@@ -12,6 +10,11 @@
 	
 	The Rcpp-modules vignette documents the feature
 	
+	o	Rcpp.package.skeleton has been improved to generate a package using 
+	an Rcpp module, controlled by the "module" argument
+
+	o	Evaluating a call inside an environment did not work properly
+	
 	o	cppfunction has been withdrawn since the introduction of the more 
 	flexible cxxfunction in the inline package. Rcpp no longer depend
 	on inline since many uses of Rcpp do not require inline at all. We still 

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/R/Module.R	2010-06-01 10:28:09 UTC (rev 1391)
@@ -155,6 +155,7 @@
 setMethod( "prompt", "Module", function(object, filename = NULL, name = NULL, ...){
 	lines <- readLines( system.file( "prompt", "module.Rd", package = "Rcpp" ) )
 	if( is.null(name) ) name <- .Call( "Module__name", object at pointer, PACKAGE = "Rcpp" )
+	if( is.null(filename) ) filename <- sprintf( "%s-module.Rd", name )
 	lines <- gsub( "NAME", name, lines )
 	
 	info <- functions( object )

Modified: pkg/Rcpp/R/Rcpp.package.skeleton.R
===================================================================
--- pkg/Rcpp/R/Rcpp.package.skeleton.R	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/R/Rcpp.package.skeleton.R	2010-06-01 10:28:09 UTC (rev 1391)
@@ -27,7 +27,17 @@
 	if( !length(list) ){
 		fake <- TRUE
 		assign( "Rcpp.fake.fun", function(){}, envir = env )
+		if( example_code ){
+			assign( "rcpp_hello_world", function(){}, envir = env )
+		}
+		remove_hello_world <- TRUE
 	} else {
+		if( ! "rcpp_hello_world" %in% list ){
+			call[["list"]] <- c( "rcpp_hello_world", call[["list"]] )
+			remove_hello_world <- TRUE
+		} else{
+			remove_hello_world <- FALSE
+		}
 		fake <- FALSE
 	}
 	
@@ -44,7 +54,7 @@
 	}
 	
 	if( fake ){
-		call[["list"]] <- "Rcpp.fake.fun"
+		call[["list"]] <- c( if( isTRUE(example_code)) "rcpp_hello_world" , "Rcpp.fake.fun" )
 	}
 	
 	tryCatch( eval( call, envir = env ), error = function(e){
@@ -59,8 +69,12 @@
 	# Add Rcpp to the DESCRIPTION
 	DESCRIPTION <- file.path( root, "DESCRIPTION" )
 	if( file.exists( DESCRIPTION ) ){
+		depends <- c( 
+			if( isTRUE(module) ) "methods", 
+			sprintf( "Rcpp (>= %s)", packageDescription("Rcpp")[["Version"]] )
+		) 
 		x <- cbind( read.dcf( DESCRIPTION ), 
-			"Depends" = sprintf( "Rcpp (>= %s)", packageDescription("Rcpp")[["Version"]]  ), 
+			"Depends" = paste( depends, collapse = ", ") , 
 			"LinkingTo" = "Rcpp", 
 			"SystemRequirements" = "GNU make" )
 		write.dcf( x, file = DESCRIPTION )
@@ -117,6 +131,15 @@
 		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( 
+			system.file("skeleton", "rcpp_hello_world.Rd", package = "Rcpp" ), 
+			hello.Rd
+			)
+		message( " >> added Rd file for rcpp_hello_world")
+		
 	}
 	
 	if( isTRUE( module ) ){
@@ -135,13 +158,21 @@
 		message( " >> copied the example module " )
 		
 	}
+	
+	lines <- readLines( package.doc <- file.path( root, "man", sprintf( "%s-package.Rd", name ) ) )
+	lines <- sub( "~~ simple examples", "%% ~~ simple examples", lines )
+	writeLines( lines, package.doc )
+	
 	if( fake ){
 		rm( "Rcpp.fake.fun", envir = env )
 		unlink( file.path( root, "R"  , "Rcpp.fake.fun.R" ) )
 		unlink( file.path( root, "man", "Rcpp.fake.fun.Rd" ) )
-		
 	}
 	
+	if( isTRUE(remove_hello_world) ){
+		rm( "rcpp_hello_world", envir = env )
+	}
+	
 	invisible( NULL )
 }
 

Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2010-06-01 10:28:09 UTC (rev 1391)
@@ -29,6 +29,9 @@
 		sprintf( "\\\\href{%s%s/html/%s.html}{\\\\texttt{%s}}", root, package, page, text )
 	}
 }
+linkS4class <- function( cl, package, text = cl, root = "http://finzi.psych.upenn.edu/R/library/" ){
+	link( sprintf("%s-class", cl), package, text, root )
+}
 @
 
 \begin{document}
@@ -456,9 +459,11 @@
 
 \section{Using modules in other packages}
 
+\subsection{namespace import/export}
+
 When using \pkg{Rcpp} modules in a packages, the client package needs to 
 import a set of classes from \pkg{Rcpp}. This is achieved by adding the 
-following line to the \texttt{NAMESPACE} file. 
+following line to the \texttt{NAMESPACE} file.
 
 <<echo=FALSE,eval=TRUE>>=
 options( prompt = " ", continue = " " )
@@ -488,10 +493,27 @@
 options( prompt = "> ", continue = "+ " )
 @
 
+\subsection{support for modules in skeleton generator}
+
 The \Sexpr{link("Rcpp.package.skeleton")} function has been improved to help
 \pkg{Rcpp} modules. When the \texttt{module} argument is set to \texttt{TRUE}, 
 the skeleton generator installs code that uses a simple module. 
 
+<<eval=FALSE>>=
+Rcpp.package.skeleton( "testmod", module = TRUE )
+@
+
+\subsection{module documentation}
+
+\pkg{Rcpp} defines a \Sexpr{link("prompt")} method for the 
+\Sexpr{linkS4class("Module")} class, allowing generation of a skeleton of an Rd
+file containing some information about the module.
+
+<<eval=FALSE>>=
+yada <- Module( "yada" )
+prompt( yada, "yada-module.Rd" )
+@
+
 \section{Future extensions}
 
 \texttt{Boost.Python} has many more features that we would like to port 

Modified: pkg/Rcpp/inst/prompt/module.Rd
===================================================================
--- pkg/Rcpp/inst/prompt/module.Rd	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/inst/prompt/module.Rd	2010-06-01 10:28:09 UTC (rev 1391)
@@ -1,13 +1,11 @@
 \name{NAME}
 \alias{NAME}
-\docType{data}
 \title{
 	Rcpp module: %% ~~ Name of the module ~~
 }
 \description{
 	Rcpp module %%  ~~ A concise description of the module ~~
 }
-\usage{data(yada)}
 \details{
 	The module contains the following items: 
 	

Added: pkg/Rcpp/inst/skeleton/rcpp_hello_world.Rd
===================================================================
--- pkg/Rcpp/inst/skeleton/rcpp_hello_world.Rd	                        (rev 0)
+++ pkg/Rcpp/inst/skeleton/rcpp_hello_world.Rd	2010-06-01 10:28:09 UTC (rev 1391)
@@ -0,0 +1,17 @@
+\name{rcpp_hello_world}
+\alias{rcpp_hello_world}
+\docType{package}
+\title{
+Simple function using Rcpp
+}
+\description{
+Simple function using Rcpp
+}
+\usage{
+rcpp_hello_world()	
+}
+\examples{
+\dontrun{
+rcpp_hello_world()
+}
+}

Modified: pkg/Rcpp/inst/skeleton/yada.Rd
===================================================================
--- pkg/Rcpp/inst/skeleton/yada.Rd	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/inst/skeleton/yada.Rd	2010-06-01 10:28:09 UTC (rev 1391)
@@ -1,13 +1,11 @@
 \name{yada}
 \alias{yada}
-\docType{data}
 \title{
-	Rcpp module: %% ~~ Name of the module ~~
+	Rcpp module yada
 }
 \description{
-	Rcpp module %%  ~~ A concise description of the module ~~
+	Rcpp module yada
 }
-\usage{data(yada)}
 \details{
 	The module contains the following items: 
 	

Modified: pkg/Rcpp/inst/skeleton/zzz.R
===================================================================
--- pkg/Rcpp/inst/skeleton/zzz.R	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/inst/skeleton/zzz.R	2010-06-01 10:28:09 UTC (rev 1391)
@@ -1,14 +1,14 @@
 
 # grab the namespace
-NAMESPACE <- environment()
+.NAMESPACE <- environment()
 
 # dummy module, will be replace later
 yada <- new( "Module" )
 
 .onLoad <- function(pkgname, libname){
 	# load the module and store it in our namespace
-	unlockBinding( "yada" , NAMESPACE )
-	assign( "yada",  Module( "yada" ), NAMESPACE )
-	lockBinding( "yada", NAMESPACE )
+	unlockBinding( "yada" , .NAMESPACE )
+	assign( "yada",  Module( "yada" ), .NAMESPACE )
+	lockBinding( "yada", .NAMESPACE )
 }
 

Modified: pkg/Rcpp/man/Rcpp.package.skeleton.Rd
===================================================================
--- pkg/Rcpp/man/Rcpp.package.skeleton.Rd	2010-06-01 09:06:32 UTC (rev 1390)
+++ pkg/Rcpp/man/Rcpp.package.skeleton.Rd	2010-06-01 10:28:09 UTC (rev 1391)
@@ -63,7 +63,12 @@
 }
 \examples{
 \dontrun{
+# simple package
 Rcpp.package.skeleton( "foobar" )
+
+# package with a module
+Rcpp.package.skeleton( "testmod", module = TRUE )
+
 }
 }
 \keyword{ programming }



More information about the Rcpp-commits mailing list