[Rcpp-commits] r1343 - in pkg/Rcpp/inst/doc: . snippets
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu May 27 15:51:42 CEST 2010
Author: romain
Date: 2010-05-27 15:51:41 +0200 (Thu, 27 May 2010)
New Revision: 1343
Added:
pkg/Rcpp/inst/doc/modules.bib
Modified:
pkg/Rcpp/inst/doc/Makefile
pkg/Rcpp/inst/doc/Rcpp-modules.Rnw
pkg/Rcpp/inst/doc/snippets/WorldModule.cpp
pkg/Rcpp/inst/doc/snippets/WorldModuleR.R
Log:
add references and document using function that take a pointer as their first argument
Modified: pkg/Rcpp/inst/doc/Makefile
===================================================================
--- pkg/Rcpp/inst/doc/Makefile 2010-05-27 12:57:41 UTC (rev 1342)
+++ pkg/Rcpp/inst/doc/Makefile 2010-05-27 13:51:41 UTC (rev 1343)
@@ -32,6 +32,8 @@
Rcpp-modules.pdf: snippets Rcpp-modules.Rnw
( cd snippets ; Rscript highlight.R ; cd .. )
R CMD Sweave Rcpp-modules.Rnw
+ Rscript -e "tools::texi2dvi( 'Rcpp-modules.tex', pdf = TRUE, clean = FALSE )"
+ bibtex Rcpp-modules
Rscript -e "tools::texi2dvi( 'Rcpp-modules.tex', pdf = TRUE, clean = TRUE )"
rm -fr Rcpp-modules.tex
rm -fr snippets/*.tex
Modified: pkg/Rcpp/inst/doc/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules.Rnw 2010-05-27 12:57:41 UTC (rev 1342)
+++ pkg/Rcpp/inst/doc/Rcpp-modules.Rnw 2010-05-27 13:51:41 UTC (rev 1343)
@@ -68,7 +68,7 @@
\noindent
\textsl{Rcpp modules} have been introduced in version 0.8.1 of \texttt{Rcpp}
to allow programmers to simply expose c++ functions and classes to R.
- \textsl{Rcpp modules} are inspired from the \texttt{Boost.Python}
+ \textsl{Rcpp modules} are inspired from the \texttt{Boost.Python} \cite{Boost:Python}
C++ library which provides the same features (and much more) for
Python. This document is a short overview of the capabilities of modules.
}
@@ -119,7 +119,7 @@
We might want a way to create objects of this class, and use the member
functions \texttt{greet} and \texttt{set} to alter the object. External pointers
-are the perfect vessel for this, and using the
+\cite{R:exts} are the perfect vessel for this, and using the
\texttt{Rcpp:::XPtr} template from \texttt{Rcpp} we can expose the class
by exposing three functions :
@@ -187,7 +187,7 @@
Rcpp modules also provide a mechanism for exposing c++ classes. The mechanism
internally uses external pointers, but the user should consider this implementation
-details.
+details as this is properly encapsulated.
A class is exposed using the \texttt{class\_} class. The \texttt{World}
class may be exposed to R :
@@ -197,12 +197,21 @@
\texttt{class\_} is templated by the c++ class or struct that is to be exposed
to R. The parameter of the \texttt{class\_<World>} constructor is the name we will
use on the R side. It usually makes sense to use the same name as the class
-name, but this is not forced.
+name, but this is not forced, which might be useful when exposing a class
+generated from a template.
The construction of the object is then followed by two calls to the
-\texttt{method} member function of \texttt{class\_<World>}. Each call simply
-register a member function by providing the name to use on the R
-side (e.g. "greet") and the reference to the member function.
+\texttt{method} member function of \texttt{class\_<World>}. \texttt{method}
+can expose :
+\begin{itemize}
+\item member functions of the target class, such as \texttt{greet} or \texttt{set}, by
+providing the name that will be used on the R side (e.g. \texttt{greet}) and
+a pointer to the actual member function (e.g. \texttt{\&World::greet} )
+\item free funtions that take a pointer to the target class as their
+first parameter such as the C++ function \texttt{clearWorld} in the previous
+example. Again, we provide the R name for the method (\texttt{clear}) and
+a pointer to the c++ function.
+\end{itemize}
The module exposes the default constructor of the \texttt{World} class as well
to support creation of \texttt{World} objects from R. The Rcpp module assumes
@@ -215,6 +224,10 @@
\texttt{Boost.Python} has many more features that we would like to port
to Rcpp modules : class inheritance, overloading, default arguments, ...
+\section{References}
+\bibliographystyle{plain}
+\bibliography{modules}
+
\end{document}
Added: pkg/Rcpp/inst/doc/modules.bib
===================================================================
--- pkg/Rcpp/inst/doc/modules.bib (rev 0)
+++ pkg/Rcpp/inst/doc/modules.bib 2010-05-27 13:51:41 UTC (rev 1343)
@@ -0,0 +1,22 @@
+ at String{CRAN = "http://cran.r-project.org/" }
+ at String{manuals = CRAN # "doc/manuals/" }
+ at String{RCoreTeam = "{R Development Core Team}" }
+ at String{RFoundation = "R Foundation for Statistical Computing" }
+
+ at manual{R:exts,
+ author = RCoreTeam,
+ organization = RFoundation,
+ address = {Vienna, Austria},
+ year = 2009,
+ title = "Writing R extensions",
+ url = manuals # "R-exts.html"
+}
+
+ at manual{Boost:Python,
+ author = { David Abrahams and Ralf W. Grosse-Kunstleve },
+ organization = "Boost Consulting",
+ title = "Building Hybrid Systems with Boost.Python",
+ year = 2003,
+ url = "http://www.boostpro.com/writing/bpl.pdf"
+}
+
Modified: pkg/Rcpp/inst/doc/snippets/WorldModule.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/WorldModule.cpp 2010-05-27 12:57:41 UTC (rev 1342)
+++ pkg/Rcpp/inst/doc/snippets/WorldModule.cpp 2010-05-27 13:51:41 UTC (rev 1343)
@@ -8,12 +8,17 @@
std::string msg;
};
+void clearWorld( World* w){
+ w->set( "" ) ;
+}
+
RCPP_MODULE(yada){
using namespace Rcpp ;
class_<World>( "World" )
.method( "greet", &World::greet )
.method( "set", &World::set )
+ .method( "clear", &clearWorld )
;
}
Modified: pkg/Rcpp/inst/doc/snippets/WorldModuleR.R
===================================================================
--- pkg/Rcpp/inst/doc/snippets/WorldModuleR.R 2010-05-27 12:57:41 UTC (rev 1342)
+++ pkg/Rcpp/inst/doc/snippets/WorldModuleR.R 2010-05-27 13:51:41 UTC (rev 1343)
@@ -13,4 +13,6 @@
w$greet()
w$set( "hello world" )
w$greet()
+w$clear()
+w$greet()
More information about the Rcpp-commits
mailing list