Skip to content

Commit f3bcf8f

Browse files
committed
updated and expanded the Rcpp-FAQ vignette
1 parent a192096 commit f3bcf8f

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2013-11-30 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* vignettes/Rcpp-FAQ.Rnw: Updated and corrected in several spots
4+
15
2013-11-22 Dirk Eddelbuettel <edd@debian.org>
26

37
* inst/include/Rcpp/stats/nt.h: Correct expansion of (d|q|p)nt()

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Rcpp::Function, etc ...
1515
The
1616
[Rcpp-introduction](http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-introduction.pdf)
1717
vignette (also published as a [JSS paper](http://www.jstatsoft.org/v40/i08/)) provides a good
18-
entry point to Rcpp, as do the [Rcpp website](http://www.rcpp.org), the
19-
[Rcpp page](http://dirk.eddelbuettel.com/code/rcpp.html). Full documentation
18+
entry point to Rcpp as do the [Rcpp website](http://www.rcpp.org), the
19+
[Rcpp page](http://dirk.eddelbuettel.com/code/rcpp.html) and the
20+
[Rcpp Gallery](http://gallery.rcpp.org). Full documentation
2021
is provided by the [Rcpp book](http://www.rcpp.org/book/).
2122

2223
Conversion from C++ to R and back is driven by the templates `Rcpp::wrap`

inst/NEWS.Rd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
\title{News for Package 'Rcpp'}
33
\newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
44

5-
\section{Changes in [unreleased] Rcpp version 0.10.7 (2013-11-21)}{
5+
\section{Changes in [unreleased] Rcpp version 0.10.7 (2013-11-30)}{
66
\itemize{
77
\item Changes in Rcpp API:
88
\itemize{
@@ -11,6 +11,10 @@
1111
variant.
1212
\item Unit tests for \code{pnt} were added.
1313
}
14+
\item Changes in Rcpp documentation:
15+
\itemize{
16+
\item The Rcpp-FAQ vignette have been updated and expanded.
17+
}
1418
}
1519
}
1620

vignettes/Rcpp-FAQ.Rnw

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ require(highlight)
7373

7474
\abstract{
7575
\noindent This document attempts to answer the most Frequently Asked
76-
Questions (FAQ) regarding the \pkg{Rcpp} \citep{CRAN:Rcpp,JSS:Rcpp} package.
76+
Questions (FAQ) regarding the \pkg{Rcpp} \citep{CRAN:Rcpp,JSS:Rcpp,Eddelbuettel:2013:Rcpp} package.
7777
}
7878

7979
\section{Getting started}
@@ -179,7 +179,8 @@ Further steps, specific to \pkg{Rcpp}, are described in a separate vignette.
179179
vignette( "Rcpp-package" )
180180
@
181181

182-
\subsection{How do I quickly prototype my code using inline?}
182+
\subsection{How do I quickly prototype my code?}
183+
\subsubsection{Using inline}
183184
\label{using-inline}
184185

185186
The \pkg{inline} package \citep{CRAN:inline} provides the functions
@@ -218,8 +219,31 @@ fx <- cxxfunction( signature(),
218219
The \texttt{verbose} argument of \Sexpr{link("cxxfunction")} is very
219220
useful as it shows how \pkg{inline} runs the show.
220221

221-
Update: Also see question \ref{using-attributes} below about 'Rcpp
222-
Attributes' \citep{CRAN:Rcpp:Attributes}.
222+
\subsubsection{Using Rcpp Attributes}
223+
\label{using-attributes}
224+
225+
Rcpp Attributes \citep{CRAN:Rcpp:Attributes}, discussed in \faq{using-attributes} below, permits an even easier
226+
route to integrating R and C++. It provides three key functions. First, \code{evalCpp}
227+
provide a means to evaluate simple C++ expression which is often useful for
228+
small tests, or to simply check if the toolchain is set up
229+
correctly. Second, \code{cppFunction} can be used to create C++ functions
230+
for R use on the fly. Third, \code{sourceCpp} can integrate entire files in
231+
order to define multiple functions.
232+
233+
The example above can now be rewritten as:
234+
235+
<<>>=
236+
cppFunction('double accu(NumericVector x) {
237+
return(std::accumulate(x.begin(), x.end(), 0.0));
238+
}')
239+
res <- accu(seq(1, 10, by=0.5))
240+
res
241+
@
242+
243+
The \code{cppFunction} parses the supplied text, extracts the desired
244+
function names, creates the required scaffolding, compiles, links and loads
245+
the supplied code and makes it available under the selected identifier.
246+
223247

224248
\subsection{How do I convert my prototyped code to a package ?}
225249
\label{from-inline-to-package}
@@ -387,8 +411,15 @@ which is described in detail in its own vignette
387411

388412
\section{Examples}
389413

390-
The following questions were asked on the \texttt{rcpp-devel} mailing list,
391-
which is generally the best place to ask questions.
414+
The following questions were asked on the
415+
\href{https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel}{Rcpp-devel}
416+
mailing list, which is our preferred place to ask questions as it guarantees
417+
exposure to a number of advanced Rcpp users. The
418+
\href{http://stackoverflow.com/questions/tagged/rcpp}{StackOverflow tag for
419+
rcpp} is an alternative; that site is also easily searchable.
420+
421+
Several dozen fully documented examples are provided at the
422+
\href{http://gallery.rcpp.org}{Rcpp Gallery} -- which is also open for new contributions.
392423

393424
\subsection{Can I use templates with \pkg{Rcpp} and \pkg{inline} ? }
394425

@@ -423,10 +454,11 @@ fun <- cxxfunction(signature(xs="numeric", is="integer"),
423454
fun(2.2, 3L)
424455
@
425456

426-
Update: Also see question \ref{using-attributes} above about 'Rcpp
457+
Update: Also see \faq{using-attributes} above about 'Rcpp
427458
Attributes' \citep{CRAN:Rcpp:Attributes} and its \code{sourceCpp} function.
428459

429460
\subsection{Can I do matrix algebra with \pkg{Rcpp} ?}
461+
\label{matrix-algebra}
430462

431463
\begin{quote}
432464
\emph{\pkg{Rcpp} allows element-wise operations on vector and matrices through
@@ -440,15 +472,16 @@ project (if done right) involving advanced techniques such as expression
440472
templates. We currently do not plan to go in this direction, but we would
441473
welcome external help. Please send us a design document.
442474

443-
However, we have developed the \pkg{RcppArmadillo} package \citep{CRAN:RcppArmadillo} that provides a
475+
However, we have developed the \pkg{RcppArmadillo} package
476+
\citep{CRAN:RcppArmadillo,Eddelbuettel+Sanderson:2014:RcppArmadillo} that provides a
444477
bridge between \pkg{Rcpp} and \pkg{Armadillo} \citep{Sanderson:2010:Armadillo}. \pkg{Armadillo}
445478
supports binary operators on its types in a way that takes full advantage of
446479
expression templates to remove temporaries and allow chaining of
447480
operations. That is a mouthful of words meaning that it makes the code go
448481
faster by using fiendishly clever ways available via the so-called template
449482
meta programming, an advanced \proglang{C++} technique.
450-
Also, the \pkg{RcppEigen} package provides an alternative using the
451-
\href{Eigen}{http://eigen.tuxfamily.org} template library.
483+
Also, the \pkg{RcppEigen} package \citep{JSS:RcppEigen} provides an alternative using the
484+
\href{http://eigen.tuxfamily.org}{Eigen} template library.
452485

453486

454487
The following example is adapted from the examples available at the project
@@ -521,6 +554,10 @@ fx()
521554
fx()
522555
@
523556

557+
Newer versions of Rcpp also provide the actual Rmath function in the \code{R}
558+
namespace, \textsl{i.e.} as \code{R::rnorm(m,s)} to obtain a scalar
559+
random variable distributed as $N(m,s)$.
560+
524561
\subsection{Can I use NA and Inf with \pkg{Rcpp} ?}
525562

526563
\begin{quote}
@@ -548,7 +585,7 @@ fun()
548585
\end{quote}
549586

550587
\noindent Yes, via the \pkg{RcppArmadillo} package which builds upon \pkg{Rcpp} and the
551-
wonderful Armadillo library at \url{http://arma.sf.net}:
588+
wonderful Armadillo library described above in \faq{matrix-algebra}:
552589

553590
<<eval=FALSE>>=
554591
txt <- 'arma::mat Am = Rcpp::as< arma::mat >(A);
@@ -569,7 +606,7 @@ C <- mmult(A, B)
569606
Armadillo supports a full range of common linear algebra operations.
570607

571608
The \pkg{RcppEigen} package provides an alternative using the
572-
\href{Eigen}{http://eigen.tuxfamily.org} template library.
609+
\href{http://eigen.tuxfamily.org}{Eigen} template library.
573610

574611
\subsection{How do I write a plugin for \pkg{inline} ?}
575612

@@ -737,15 +774,21 @@ searching.
737774
\subsection{I like it. How can I help ?}
738775
\label{helping}
739776

740-
We maintain a list of issues in the github repository
741-
we use. \href{https://github.com/RcppCore/Rcpp/issues?state=open}.
777+
We maintain a list of
778+
\href{https://github.com/RcppCore/Rcpp/issues?state=open}{open issues in the
779+
Github repository}. We welcome pull requests and suggest that code submissions
780+
come corresponding unit tests and, if applicable, documentation.
742781

743782
If you are willing to donate time and have skills in C++, let us know. If you are
744-
willing to donate money to sponsor improvements, let us know.
783+
willing to donate money to sponsor improvements, let us know too.
745784

746785
You can also spread the word about \pkg{Rcpp}. There are many packages on CRAN
747786
that use \proglang{C++}, yet are not using \pkg{Rcpp}. You could blog about
748-
it or get the word out otherwise.
787+
it, or get the word out otherwise.
788+
789+
Last but not least the \href{http://gallery.rcpp.org}{Rcpp Gallery} is open
790+
for user contributions.
791+
749792

750793
\subsection{I don't like it. How can I help ?}
751794

@@ -761,6 +804,16 @@ request.
761804

762805
Yes. Just send us an email.
763806

807+
\subsection{Where is to code repository ?}
808+
809+
From late 2008 to late 2013, we used the
810+
\href{https://r-forge.r-project.org/scm/?group_id=155}{Subversion repository at R-Forge}
811+
which contained Rcpp and a number of related packages. It still has the full
812+
history as well as number of support files.
813+
814+
We have since switched to a \href{http://github.com/RcppCore/Rcpp}{Git
815+
repository at Github} for Rcpp (as well as RcppArmadillo and RcppEigen).
816+
764817
\bibliographystyle{plainnat}
765818
\bibliography{Rcpp}
766819

0 commit comments

Comments
 (0)