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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 1 10:57:33 CEST 2010


Author: romain
Date: 2010-06-01 10:57:32 +0200 (Tue, 01 Jun 2010)
New Revision: 1389

Added:
   pkg/Rcpp/inst/prompt/
   pkg/Rcpp/inst/prompt/module.Rd
   pkg/Rcpp/inst/skeleton/yada.Rd
Modified:
   pkg/Rcpp/NAMESPACE
   pkg/Rcpp/R/Module.R
   pkg/Rcpp/R/Rcpp.package.skeleton.R
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/inst/skeleton/rcpp_module.cpp
   pkg/Rcpp/man/Module-class.Rd
Log:
added a prompt method for modules to generate a skeleton Rd file with the list of functions and classes of the module

Modified: pkg/Rcpp/NAMESPACE
===================================================================
--- pkg/Rcpp/NAMESPACE	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/NAMESPACE	2010-06-01 08:57:32 UTC (rev 1389)
@@ -9,8 +9,8 @@
 export( Module )
 exportMethods( new )
 
-importFrom( utils, .DollarNames )
+importFrom( utils, .DollarNames, prompt )
 S3method( .DollarNames, "C++ObjectS3" )
 S3method( .DollarNames, "Module" )
-exportMethods( complete )
+exportMethods( prompt )
 

Modified: pkg/Rcpp/R/Module.R
===================================================================
--- pkg/Rcpp/R/Module.R	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/R/Module.R	2010-06-01 08:57:32 UTC (rev 1389)
@@ -94,7 +94,6 @@
 
 setMethod( "$", "C++Object", dollar_cppobject )
 
-
 Module <- function( module, PACKAGE = getPackageName(where), where = topenv(parent.frame()) ){
 	name <- sprintf( "_rcpp_module_boot_%s", module )
 	symbol <- getNativeSymbolInfo( name, PACKAGE )
@@ -146,3 +145,39 @@
 	grep( pattern, complete(x), value = TRUE )
 }
 
+setGeneric( "functions", function(object, ...) standardGeneric( "functions" ) )
+setMethod( "functions", "Module", function(object, ...){
+	.Call( "Module__funtions_arity", object at pointer, PACKAGE = "Rcpp" )
+} )
+
+
+setGeneric( "prompt" )
+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" )
+	lines <- gsub( "NAME", name, lines )
+	
+	info <- functions( object )
+	f.txt <- if( length( info ) ){
+		sprintf( "functions: \\\\describe{
+%s
+		}", paste( sprintf( "        \\\\item{%s}{ ~~ description of function %s ~~ }", names(info), names(info) ), collapse = "\n" ) )
+	} else {
+		"" 
+	}
+	lines <- sub( "FUNCTIONS", f.txt, lines )
+	
+	classes <- .Call( "Module__classes_info", object at pointer, PACKAGE = "Rcpp" )
+	c.txt <- if( length( classes ) ){
+		sprintf( "classes: \\\\describe{
+%s
+		}", paste( sprintf( "        \\\\item{%s}{ ~~ description of class %s ~~ }", names(classes), names(classes) ), collapse = "\n" ) )
+	} else {
+		"" 
+	}
+	lines <- sub( "CLASSES", c.txt, lines )
+	
+	writeLines( lines, filename )
+	invisible(NULL)
+} )
+

Modified: pkg/Rcpp/R/Rcpp.package.skeleton.R
===================================================================
--- pkg/Rcpp/R/Rcpp.package.skeleton.R	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/R/Rcpp.package.skeleton.R	2010-06-01 08:57:32 UTC (rev 1389)
@@ -124,8 +124,12 @@
 			system.file( "skeleton", "zzz.R", package = "Rcpp" ), 
 			file.path( root, "R" )
 		)
+		file.copy( 
+			system.file( "skeleton", "yada.Rd", package = "Rcpp" ), 
+			file.path( root, "man" )
+		)
+		message( " >> copied the example module " )
 		
-		message( " >> copied the example module " )
 	}
 	if( fake ){
 		rm( "Rcpp.fake.fun", envir = env )

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/inst/ChangeLog	2010-06-01 08:57:32 UTC (rev 1389)
@@ -4,6 +4,9 @@
 	in other packages (namespace, etc ...)
 	
 	* R/Rcpp.package.skeleton: added the module argument
+	
+	* R/Module.R: prompt method for Module objects to generate skeleton of an Rd
+	file with the list of functions and classes defined by the module.
 
 2010-05-30  Romain Francois <romain at r-enthusiasts.com>
 

Added: pkg/Rcpp/inst/prompt/module.Rd
===================================================================
--- pkg/Rcpp/inst/prompt/module.Rd	                        (rev 0)
+++ pkg/Rcpp/inst/prompt/module.Rd	2010-06-01 08:57:32 UTC (rev 1389)
@@ -0,0 +1,29 @@
+\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: 
+	
+	FUNCTIONS 
+	
+	CLASSES
+}
+\source{
+%% ~~ reference to a publication or URL ~~
+%% ~~ perhaps a reference to the project page of the c++ code being exposed ~~
+}
+\references{
+%% ~~ possibly secondary sources and usages ~~
+%% ~~ perhaps references to the C++ code that the module exposes ~~
+}
+\examples{
+show( NAME )
+}
+\keyword{datasets}

Modified: pkg/Rcpp/inst/skeleton/rcpp_module.cpp
===================================================================
--- pkg/Rcpp/inst/skeleton/rcpp_module.cpp	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/inst/skeleton/rcpp_module.cpp	2010-06-01 08:57:32 UTC (rev 1389)
@@ -1,5 +1,29 @@
 #include <Rcpp.h>
 
+std::string hello() {
+	throw std::range_error( "boom" ) ;
+}
+
+int bar( int x){
+	return x*2 ;
+}
+        
+double foo( int x, double y){
+	return x * y ;
+}
+
+void bla( ){
+	Rprintf( "hello\\n" ) ;
+}
+
+void bla1( int x){
+	Rprintf( "hello (x = %d)\\n", x ) ;
+}
+  
+void bla2( int x, double y){
+	Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y ) ;
+}
+
 class World {
 public:
     World() : msg("hello"){}
@@ -10,18 +34,22 @@
     std::string msg;
 };
 
-void clearWorld( World* w){
-	w->set( "" ) ;
-}
 
+
 RCPP_MODULE(yada){
 	using namespace Rcpp ;
+	                  
+	function( "hello" , &hello ) ;
+	function( "bar"   , &bar   ) ;
+	function( "foo"   , &foo   ) ;
+	function( "bla"   , &bla   ) ;
+	function( "bla1"  , &bla1   ) ;
+	function( "bla2"  , &bla2   ) ;
 	
 	class_<World>( "World" )
 		.method( "greet", &World::greet )
 		.method( "set", &World::set )
-		.method( "clear", &clearWorld )
 	;
+}                     
 
-}            
 

Added: pkg/Rcpp/inst/skeleton/yada.Rd
===================================================================
--- pkg/Rcpp/inst/skeleton/yada.Rd	                        (rev 0)
+++ pkg/Rcpp/inst/skeleton/yada.Rd	2010-06-01 08:57:32 UTC (rev 1389)
@@ -0,0 +1,38 @@
+\name{yada}
+\alias{yada}
+\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: 
+	
+	functions: \describe{
+        \item{bar}{ ~~ description of function bar ~~ }
+        \item{bla}{ ~~ description of function bla ~~ }
+        \item{bla1}{ ~~ description of function bla1 ~~ }
+        \item{bla2}{ ~~ description of function bla2 ~~ }
+        \item{foo}{ ~~ description of function foo ~~ }
+        \item{hello}{ ~~ description of function hello ~~ }
+	} 
+	
+	classes: \describe{
+        \item{World}{ ~~ description of class World ~~ }
+	}
+}
+\source{
+%% ~~ reference to a publication or URL ~~
+%% ~~ perhaps a reference to the project page of the c++ code being exposed ~~
+}
+\references{
+%% ~~ possibly secondary sources and usages ~~
+%% ~~ perhaps references to the C++ code that the module exposes ~~
+}
+\examples{
+show( yada )
+}
+\keyword{datasets}

Modified: pkg/Rcpp/man/Module-class.Rd
===================================================================
--- pkg/Rcpp/man/Module-class.Rd	2010-06-01 08:09:53 UTC (rev 1388)
+++ pkg/Rcpp/man/Module-class.Rd	2010-06-01 08:57:32 UTC (rev 1389)
@@ -3,6 +3,7 @@
 \docType{class}
 \alias{Module-class}
 \alias{$,Module-method}
+\alias{prompt,Module-method}
 
 \title{Rcpp modules}
 \description{
@@ -18,8 +19,9 @@
 }
 \section{Methods}{
   \describe{
-    \item{$}{\code{signature(x = "Module")}: extract a function or a class from the module }
-	 }
+    \item{$}{\code{signature(x = "Module")}: extract a function or a class from the module. }
+    \item{prompt}{\code{signature(object = "Module")}: generates skeleton of a documentation for a Module. }
+  }
 }
 \seealso{
 	\code{\link{Module}}



More information about the Rcpp-commits mailing list