Git Product home page Git Product logo

rgen's Introduction

R-CMD-check 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.

rgen is available on CRAN and GitHub.

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, install the package from CRAN with:

install.packages("rgen")

or from GitHub by:

install.packages("remotes")
remotes::install_github("coatless-rpkg/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

rgen's People

Contributors

coatless avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rgen's Issues

Add Rcpp.plugin.maker hook

To allow for stand-alone script development, we'll need to add in a call to register the package with Rcpp attributes via the Rcpp.plugin.maker()

Add in $(SHLIB_OPENMP_CFLAGS) when Armadillo 7.900.0 ships with OpenMP 3.0 support for basic element-wise ops.

Export function calls into R?

Should these sampling distributions be available on call to R? With the header-library behind rgen, we can create a wrapper into R this way...

Downside: Two sets of documentation.. >.<

Improve readme & add news

README is a bit vague...

Use:

  • Package Intro
    • Supported Distributions
    • Installation Instructions
    • Using the package
      • standalone example
      • packaging example

Need to also add in a NEWS file to track changes / allow for release posts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.