[Rcpp-commits] r2053 - papers/rjournal
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sat Aug 28 23:52:42 CEST 2010
Author: edd
Date: 2010-08-28 23:52:42 +0200 (Sat, 28 Aug 2010)
New Revision: 2053
Modified:
papers/rjournal/EddelbuettelFrancois.tex
Log:
updated as per the editor and reviewers comments -- still more to do
Modified: papers/rjournal/EddelbuettelFrancois.tex
===================================================================
--- papers/rjournal/EddelbuettelFrancois.tex 2010-08-28 21:51:41 UTC (rev 2052)
+++ papers/rjournal/EddelbuettelFrancois.tex 2010-08-28 21:52:42 UTC (rev 2053)
@@ -45,15 +45,14 @@
\subsection{Historical Context}
-\pkg{Rcpp} first appeared in 2005 as a contribution to the \pkg{RQuantLib}
-package \citep{eddelbuettelkhan09:rquantlib} before becoming a CRAN
-package in early 2006. Several releases followed in quick succession; all of
-these were under the name \pkg{Rcpp}. The package was then renamed to
-\pkg{RcppTemplate} and several more releases followed during 2006 under the
-new name. However, no new releases or updates were made during 2007, 2008
-and most of 2009.
+\pkg{Rcpp} first appeared in 2005 as a contribution (by Samperi) to the
+\pkg{RQuantLib} package \citep{cran:rquantlib} before becoming a CRAN package
+in early 2006. Several releases (all by Samperi) followed in quick succession
+under the name \pkg{Rcpp}. The package was then renamed to
+\pkg{RcppTemplate}; several more releases followed during 2006 under the new
+name. However, no new releases were made during 2007 or 2008.
-Given the continued use of the package, it was revitalized. New
+Given the continued use of the package, Eddelbuettel decided to revitalize it. New
releases, using the initial name \pkg{Rcpp}, started in November 2008. These
already included an improved build and distribution process, additional
documentation, and new functionality---while retaining the existing
@@ -61,10 +60,11 @@
the next section) which will be maintained for the foreseeable future.
Yet C++ coding standards continued to evolve \citep{meyers:effectivecplusplus}.
-So starting in 2009 the codebase was significantly extended and numerous new
+In 2009, Eddelbuettel and Fran\c{c}ois started to significantly extend the codebase and numerous new
features were added. Several of these are described below in the section on
-the `new \pkg{Rcpp}' interface. This new API is our current focus, and we
-intend to both extend and support it going forward.
+the `new \pkg{Rcpp}' interface, as well as in the seven vignettes included
+with the package. This new API is our current focus, and we
+intend to both extend and support it in future development of the package.
\subsection{Comparison}
@@ -84,26 +84,26 @@
\citep{armstrong09:RObjects} are all implemented using C++ templates.
However, neither has matured to the point of a CRAN release and it is
unclear how much usage these packages are seeing beyond their own authors.
-%
+
CXXR \citep{runnalls09:cxxr} comes to this topic from the other side:
its aim is to completely refactor R on a stronger C++ foundation.
CXXR is therefore concerned with all aspects of the R interpreter,
-REPL loop, threading---and object interchange between R and C++ is but one
+REPL, threading---and object interchange between R and C++ is but one
part. A similar approach is discussed by \cite{templelang09:modestproposal}
who suggests making low-level internals extensible by package developers in
order to facilitate extending \R.
-%
+
Another slightly different angle is offered by
\cite{templelang09:rgcctranslationunit} who uses compiler output for
references on the code in order to add bindings and wrappers.
%
-Lastly, the \pkg{RcppTemplate} package \citep{samperi09:rcpptemplate}
-recently introduced a few new ideas yet decided to break with the
-`classic \pkg{Rcpp}' API.
+Lastly, the \pkg{cxxPack} package \citep{cran:cxxPack} builds on top of
+\pkg{Rcpp} and adds a small collection of diverse functions.
-A critical comparison of these packages that addresses relevant aspects such
-API features, performance, usability and documentation would be a welcome
-addition to the literature, but is beyond the scope of this article.
+%DE: Removed per editor
+%A critical comparison of these packages that addresses relevant aspects such
+%API features, performance, usability and documentation would be a welcome
+%addition to the literature, but is beyond the scope of this article.
\section{Classic Rcpp API}
\label{sec:classic_rcpp}
@@ -156,26 +156,29 @@
We can highlight several aspects. First, only a single header file
\code{Rcpp.h} is needed to use the \pkg{Rcpp} API. Second, given two
-\code{SEXP} types, a third is returned.
-Third, both inputs are converted to templated\footnote{C++ templates
-allow functions or classes to be written somewhat independently from the
-template parameter. The actual class is instantiated by the compiler
-by replacing occurrences of the templated parameter(s).}
-C++ vector types, here a standard \code{double}
-type is used to create a vector of doubles from the template type.
-Fourth, the usefulness of these classes can be seen when we query the
-vectors directly for their size---using the \code{size()} member function---in
-order to reserve a new result type of appropriate length whereas use based
-on C arrays would have required additional parameters for the length of
-vectors $a$ and $b$, leaving open the possibility of mismatches between the
-actual length and the length reported by the programmer.
-Fifth, the computation itself is straightforward embedded looping just as in the
-original examples in the 'Writing R Extensions' manual \citep{R:exts}.
-Sixth, a return type (\code{RcppResultSet}) is prepared as a named
-object which is then
-converted to a list object that is returned. We should note that the
-\code{RcppResultSet} supports the return of numerous (named) objects which can
-also be of different types.
+\code{SEXP} types, a third is returned. Third, both inputs are converted to
+templated\footnote{C++ templates allow functions or classes to be written
+ somewhat independently from the template parameter. The actual class is
+ instantiated by the compiler by replacing occurrences of the templated
+ parameter(s). A simple example would be a templated function
+ \texttt{abs(T)} which returns the negative of the template argument $T$
+ when $T<0$ and $T$ otherwise. While the source code is written with a
+ `templated' type $T$, the compiler will create a concrete instance using an
+ \texttt{int} or \texttt{double} type dependent on the context is which the
+ code is called.} C++ vector types, here a standard \code{double} type is
+used to create a vector of doubles from the template type. Fourth, the
+usefulness of these classes can be seen when we query the vectors directly
+for their size---using the \code{size()} member function---in order to
+reserve a new result type of appropriate length whereas use based on C arrays
+would have required additional parameters for the length of vectors $a$ and
+$b$, leaving open the possibility of mismatches between the actual length and
+the length reported by the programmer. Fifth, the computation itself is
+straightforward embedded looping just as in the original examples in the
+'Writing R Extensions' manual \citep{R:exts}. Sixth, a return type
+(\code{RcppResultSet}) is prepared as a named object which is then converted
+to a list object that is returned. We should note that the
+\code{RcppResultSet} supports the return of numerous (named) objects which
+can also be of different types.
We argue that this usage is already much easier to read, write and debug than the
C macro-based approach supported by R itself. Possible performance issues and
@@ -271,8 +274,8 @@
Memory is allocated by \code{allocVector}; we must also supply it with
the type of data (\code{REALSXP}) and the number of elements. Once
allocated, the \code{ab} object must be protected from garbage
-collection\footnote{Since the garbage collection can be triggered at any time, not
-protecting an object means its memory might be reclaimed too soon.}.
+collection.%\footnote{Since the garbage collection can be triggered at any time, not
+%protecting an object means its memory might be reclaimed too soon.}.
Lastly, the \code{REAL} macro returns a pointer to the
beginning of the actual array; its indexing does not resemble either R or
C++.
@@ -339,11 +342,12 @@
\subsection{C++ to R : wrap}
The C++ to R conversion is performed by the \code{Rcpp::wrap} templated
-function. It uses advanced template meta programming techniques\footnote{A
- discussion of template meta programming is beyond the scope of this
- article.} to convert a wide and extensible set of types and classes to the
-most appropriate type of R object. The signature of the \code{wrap} template
-is:
+function. It uses advanced template metaprogramming techniques\footnote{A
+ discussion of template metaprogramming
+ \citep{Vandevoorde+Josuttis:2003,Abrahams+Gurtovoy:2004} is beyond the
+ scope of this article.} to convert a wide and extensible set of types and
+classes to the most appropriate type of R object. The signature of the
+\code{wrap} template is:
\begin{example}
template <typename T>
@@ -448,7 +452,7 @@
requested type.
In the second part of the example, the \code{operator[]}
-delegates to wrap the production of an R object based on the
+delegates to \code{wrap} the production of an R object based on the
type that is passed in (\code{std::map<std::string,std::string>}),
and then assigns the object to the requested name.
@@ -514,7 +518,7 @@
\end{minipage}
\caption{\pkg{Rcpp} versus the R API: Four ways of calling \code{rnorm(10L, sd=100)} in C / C++.
We have removed the \code{Rcpp::} prefix from the
- examples for readability; this corresponds to adding a statement
+ examples for readability; this corresponds to adding a directive
\texttt{using namespace Rcpp;} in the code}
\label{fig:rnormCode}
\end{table*}
@@ -522,7 +526,7 @@
The next example shows how to use \pkg{Rcpp} to emulate the R code
\code{rnorm(10L, sd=100.0)}.
%
-As shown in table~\ref{fig:rnormCode}, the code can be expressed in several
+As shown in Table~\ref{fig:rnormCode}, the code can be expressed in several
ways in either \pkg{Rcpp} or the standard R API. The first version shows the
use of the \code{Environment} and \code{Function} classes by
\pkg{Rcpp}.
@@ -541,7 +545,7 @@
Extending R with compiled code also needs to address how to reliably compile,
link and load the code. While using a package is preferable in the long run,
-it may be too involved for for quick explorations. An alternative is
+it may be too involved for quick explorations. An alternative is
provided by the \pkg{inline} package \citep{cran:inline} which compiles,
links and loads a C, C++ or Fortran function---directly from the R prompt
using a simple function \code{cfunction}. It was recently extended to work
@@ -617,7 +621,7 @@
The following code illustrates how \pkg{Rcpp} might be used
to emulate a
-simpler\footnote{The version of \code{lapply} does not include usage of the
+simpler\footnote{The version of \code{lapply} does not allow use of the
ellipsis (\code{...}).} version of \code{lapply}
using the \code{transform} algorithm from the STL.
@@ -697,7 +701,7 @@
overcome this problem, \pkg{Rcpp} uses the \code{Rcpp::Evaluator}
class to evaluate an expression with an R-level \code{tryCatch}
block. The error, if any, that occurs while evaluating the
-function is then translated in terms of an C++ exception.
+function is then translated into an C++ exception.
\section{Performance comparison}
@@ -727,7 +731,7 @@
In order to achieve maximum efficiency, the reference implementation
extracts the underlying array pointer \code{double*} and works
-with pointer arithmetics, which is a built-in operation as opposed to
+with pointer arithmetic, which is a built-in operation as opposed to
calling the \code{operator[]} on a user-defined class which has to
pay the price of object encapsulation.
@@ -846,7 +850,7 @@
\email{edd at debian.org}
\address{Romain Fran\c{c}ois\\
- Professionnal R Enthusiast\\
+ Professional R Enthusiast\\
3 rue Emile Bonnet, 34 090 Montpellier\\
FRANCE}\\
\email{romain at r-enthusiasts.com}
More information about the Rcpp-commits
mailing list