GHK Algorithm for Simulation of Multivariate Normal Rectangle Probabilities in RCPP

When starting new projects in RCPP, the biggest hurdle is to re-implement existing code snippets for standard tasks that are not (yet) part of RCPP. I have implementations for certain full-conditional draws coded up efficiently in vectorized R. I have implementations in plain C and C++ that were previously accessed in compiled form throug dyn.load or .C. I started to slowly transition more and more snippets to RCPP C++.
Here's a reimplementation of the GHK simulator from bayesm. Some minor mofidications were necessary. Now it is ready for implementation within larger RCPP projects.

Have fun writing MCMC samplers or doing simulated ML.

brackets [[ for RCPP

One cool feature of R is the ease of data handling. Lists, data frames and matrices can easily be accessed and indexed, making vector-oriented programming easy. When switching over to C/RCPP, things are a little different. Personally, I like the Armadillo library, since it gets me as close to R or Matlab as possible. One thing I have been missing though is quick access to matrix elements through brackets and logical statements. I have written some functions for illustration:

Try it out