Articles by Rcpp Gallery

Calling R Functions from C++

January 5, 2013 | Rcpp Gallery

At its very essence, Rcpp permits easy access to native R objects at the C++ level. R objects can be simple vectors, list or matrices; compound data structures created from these; objects of S3, S4 or Reference Class vintage; or language objects a... [Read more...]

Armadillo eigenvalues

January 4, 2013 | Rcpp Gallery

Today a (slightly confused) question on StackOverflow wondered how to access R’s facilities for eigenvalues calculations from C code. For this, we need to step back and consider how this is done. In fact, R farms the calculation out to the BLAS.... [Read more...]

Accessing environments

January 3, 2013 | Rcpp Gallery

Extending R with C++ code by using Rcpp typically involves function calls by leveraging the existing .Call() interface of the R API. Passing values back and forth is then done in manner similar to programming with functions. However, on occassion it i... [Read more...]

Armadillo subsetting

January 2, 2013 | Rcpp Gallery

A StackOverflow question asked how convert from arma::umat to arma::mat. The former is format used for find and other logical indexing. For the particular example at hand, a call to the conv_to converter provided the solution. We rewrite the answer he... [Read more...]

STL for_each and generalized iteration

January 1, 2013 | Rcpp Gallery

The STL contains a very general looping or sweeping construct in the for_each algorith. It can be used with function objects (such as the simple square function used here) but also with custom class which can be used to keep to keep state. #include &lt... [Read more...]

Sugar Functions head and tail

January 1, 2013 | Rcpp Gallery

The R functions head and tail return the first (last) n elements of the input vector. With Rcpp sugar, the functions head and tail work the same way as they do in R. Here we use std::sort from the STL and then tail to return the top n items (... [Read more...]

STL random_sample

December 31, 2012 | Rcpp Gallery

An earlier post looked at random shuffle for permutations. The STL also supports creation of random samples. Alas, it seems that this functionality has not been promoted to the C++ standard yet — so we will have to do with what is an extensions ... [Read more...]

STL random_shuffle for permutations

December 30, 2012 | Rcpp Gallery

The STL also contains random sampling and shuffling algorithms. We start by looking at random_shuffle. There are two forms. The first uses an internal RNG with its own seed; the second form allows for a function object conformant to the STL’s re... [Read more...]

STL Transform

December 28, 2012 | Rcpp Gallery

The STL transform function can be used to pass a single function over a vector. Here we use a simple function square(). #include using namespace Rcpp; inline double square(double x) { return x*x ; } // [[Rcpp::export]] std::vector [Read more...]
1 4 5 6

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)