MyNixOS website logo
Description

Random Sampling Distribution C++ Routines for Armadillo.

Provides popular sampling distributions C++ routines based in armadillo through a header file approach.

Build Status Downloads CRAN License

rgen - C++ Headers for Sampling Distributions

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.

Supported Distributions

Presently, 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.

Installation of rgen

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:

# install.packages("devtools")

devtools::install_github("coatless/rgen")

Using rgen

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.

Standalone file usage

Within the 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 rgen.

#include <RcppArmadillo.h> 
// [[Rcpp::depends(RcppArmadillo)]]

#include <rgen.h> 
// [[Rcpp::depends(rgen)]]

Note: Since rgen relies upon RcppArmadillo, you must include the RcppArmadillo.h header and include the traditional Rcpp dependency attribute, e.g. // [[Rcpp::depends(RcppArmadillo)]].

For example, the following would allow for you to sample from an inverse wishart distribution:

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

#include <rgen.h>
// [[Rcpp::depends(rgen)]]

// Surface the riwishart function in the rgen package into R.
// [[Rcpp::export]]
arma::mat riwishart(unsigned int df, const arma::mat& S) {
    return rgen::riwishart(df, S);
}

/*** R
# Set seed for reproducibility
set.seed(111)

# Call the C++ function from R
riwishart(3, diag(2))
*/

Package usage

To use rgen in your R package, modify the DESCRIPTION file by adding:

LinkingTo: Rcpp, RcppArmadillo, rgen
Imports:
    Rcpp (>= 0.12.10)

To use C++11, you may wish to add the following to your src/Makevars and src/Makevars.win file:

CXX_STD = CXX11
Metadata

Version

0.0.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows