Provides popular sampling distributions C++ routines based in armadillo through a header file approach.
The repository houses random distribution sampling routines based in
armadillo. These routines connect into R's seed generator using
RcppArmadillo. This package was spun off from the
r-to-armadillo project as it contained more direct references to internal R seeds.
rgen provides random sample functionality from:
Most notably, this is a header-only collection of functions. Therefore, this package can be linked to a pre-existing package instead of having to copy and paste the header files directly into your project's source.
rgen is currently only available on GitHub, but should also be available on CRAN shortly.
To install the package, you must first have a compiler on your system that is compatible with R.
For help on obtaining a compiler consult:
With a compiler in hand, one can then install the package from GitHub by:
There are two ways to use
rgen. The first is to use
rgen in a standalone script. The script is typically built using
sourceCpp(). The second approach allows for
rgen to be used within an R package.
C++ file, the
rgen package provides an Rcpp plugins' depends statement that must be included after
rgen.h header. This plugin statement indicates that a dependency is
// [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::depends(rgen)]]
rgen relies upon
RcppArmadillo, you must include the
RcppArmadillo.h header and include the traditional Rcpp dependency attribute, e.g.
For example, the following would allow for you to sample from an inverse wishart distribution:
// [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::depends(rgen)]]// Surface the riwishart function in the rgen package into R.// [[Rcpp::export]]arma::mat/*** R# Set seed for reproducibilityset.seed(111)# Call the C++ function from Rriwishart(3, diag(2))*/
rgen in your R package, modify the
DESCRIPTION file by adding:
LinkingTo: Rcpp, RcppArmadillo, rgen Imports: Rcpp (>= 0.12.10)
C++11, you may wish to add the following to your
CXX_STD = CXX11