Blog Archives

Using the RcppArmadillo-based Implementation of R’s sample()

April 12, 2013
By
Using the RcppArmadillo-based Implementation of R’s sample()

Overview and Motivation All of R’s (r*, p*, q*, d*) distribution functions are available in C++ via the R API. R is written in C, and the R API has no concept of a vector (at least not in the STL sense). Consequently, R’s sample() function can’t just be exported via the R API, despite its importance and usefulness....

Read more »

Using the RcppArmadillo-based Implementation of R’s sample()

April 12, 2013
By
Using the RcppArmadillo-based Implementation of R’s sample()

Overview and Motivation All of R’s (r*, p*, q*, d*) distribution functions are available in C++ via the R API. R is written in C, and the R API has no concept of a vector (at least not in the STL sense). Consequently, R’s sample() function can’t just be exported via the R API, despite its importance and usefulness....

Read more »

Dynamic Wrapping and Recursion with Rcpp

April 8, 2013
By
Dynamic Wrapping and Recursion with Rcpp

We can leverage small parts of the R’s C API in order to infer the type of objects directly at the run-time of a function call, and use this information to dynamically wrap objects as needed. We’ll also present an example of recursing through a list. To get a basic familiarity with the main functions exported from R API, I...

Read more »

Dynamic Wrapping and Recursion with Rcpp

April 8, 2013
By
Dynamic Wrapping and Recursion with Rcpp

We can leverage small parts of the R’s C API in order to infer the type of objects directly at the run-time of a function call, and use this information to dynamically wrap objects as needed. We’ll also present an example of recursing through a list. To get a basic familiarity with the main functions exported from R API, I...

Read more »

Using bigmemory with Rcpp

March 14, 2013
By
Using bigmemory with Rcpp

The bigmemory package allows users to create matrices that are stored on disk, rather than in RAM. When an element is needed, it is read from the disk and cached in RAM. These objects can be much larger than native R matrices. Objects stored as such larger-than-RAM matrices are defined in the big.matrix class and they are designed...

Read more »

Using bigmemory with Rcpp

March 14, 2013
By
Using bigmemory with Rcpp

The bigmemory package allows users to create matrices that are stored on disk, rather than in RAM. When an element is needed, it is read from the disk and cached in RAM. These objects can be much larger than native R matrices. Objects stored as such larger-than-RAM matrices are defined in the big.matrix class and they are designed...

Read more »

Generating a multivariate gaussian distribution using RcppArmadillo

March 12, 2013
By
Generating a multivariate gaussian distribution using RcppArmadillo

There are many ways to simulate a multivariate gaussian distribution assuming that you can simulate from independent univariate normal distributions. One of the most popular method is based on the Cholesky decomposition. Let’s see how Rcpp and Armadillo perform on this task. #include <RcppArmadillo.h> // ] using namespace Rcpp; // ] arma::mat mvrnormArma(int n, arma::vec mu, arma::mat sigma) { int ncols...

Read more »

Generating a multivariate gaussian distribution using RcppArmadillo

March 12, 2013
By
Generating a multivariate gaussian distribution using RcppArmadillo

There are many ways to simulate a multivariate gaussian distribution assuming that you can simulate from independent univariate normal distributions. One of the most popular method is based on the Cholesky decomposition. Let’s see how Rcpp and Armadillo perform on this task. #include <RcppArmadillo.h> // ] using namespace Rcpp; // ] arma::mat mvrnormArma(int n, arma::vec mu, arma::mat sigma) { int ncols...

Read more »

Using Rcpp with Boost.Regex for regular expression

March 1, 2013
By
Using Rcpp with Boost.Regex for regular expression

Gabor asked about Rcpp use with regular expression libraries. This post shows a very simple example, based onone of the Boost.RegEx examples. We need to set linker options. This can be as simple as Sys.setenv("PKG_LIBS"="-lboost_regex") With that, the following example can be built: // cf www.boost.org/doc/libs/1_53_0/libs/regex/example/snippets/credit_card_example.cpp #include <Rcpp.h> #include <string> #include <boost/regex.hpp> bool validate_card_format(const std::string& s) { static const boost::regex e("(\\d{4}){3}\\d{4}"); ...

Read more »

Using Rcpp with Boost.Regex for regular expression

March 1, 2013
By
Using Rcpp with Boost.Regex for regular expression

Gabor asked about Rcpp use with regular expression libraries. This post shows a very simple example, based onone of the Boost.RegEx examples. We need to set linker options. This can be as simple as Sys.setenv("PKG_LIBS"="-lboost_regex") With that, the following example can be built: // cf www.boost.org/doc/libs/1_53_0/libs/regex/example/snippets/credit_card_example.cpp #include <Rcpp.h> #include <string> #include <boost/regex.hpp> bool validate_card_format(const std::string& s) { static const boost::regex e("(\\d{4}){3}\\d{4}"); ...

Read more »