# RcppTN

## What?

**RcppTN** is an R package that relies on the fantastic
**Rcpp** R package. The
single, clear goal of **RcppTN** is to facilitate working with truncated Normal
distributions. **RcppTN** has grown out of my own need to draw from arbitrary
truncated Normal distributions and calculate the associated moments of these
distributions.

## Why?

Other RNGs for the truncated Normal distribution exist, so why another? Other RNGs didn’t meet my needs. The existing R implementations (even if written in C or C++) did not readily expose themselves at the compiled code level. That meant my compiled code could not use the same RNG as my R code. The existing C++ implementations didn’t have an R–level interface and didn’t obey R’s RNG state. That meant lots of work spent on a retro-fit.

My solution was an implementation designed for use at the R level and the C++ level in R-based computation.

## **RcppTN** is:

*fast*

- the R package implements an efficient sampler (Robert 1995) in an efficient language (C++)

*efficient*

- copies are avoided with references and STL constructs

*reproducible*

- the RNG at the R level and the C++ level are in sync with each other and the rest of an R session
- the RNG is easily seeded with R’s
`set.seed()`

*accessible*

- R–level and C++–level interfaces call the same underlying code
- the R and C++ interfaces are simple to use in your own R or C++ code thanks to
**Rcpp**

*tested*

- the R package has a growing suite of unit tests testing for correctness
- C++ memory operations profiled with
*valgrind*, only clean code is released into the wild

## Interested?

For the entire project, see the github repo.

For an explanation on how to use

**RcppTN**at the R or C++ level, see the “using” vignette.For a performance benchmark of

**RcppTN**to alternatives, see the “speed” vignette.

## Current Version

The current release of the package is **RcppTN** 0.1-6