[Rcpp-devel] How to use functions from a R library in .cpp file

Li Li llis at unm.edu
Fri Jan 23 19:01:35 CET 2015


Dear Yixuan,

Thank you very much.

I embedded the following into the program and it worked. The only thing changed was that I added "Rcpp::” so it could read in a cpp file.

Rcpp::NumericVector test()
{
    Rcpp::Environment pkg("package:mvtnorm");
    Rcpp::Function pmvnorm = pkg["pmvnorm"];
    Rcpp::NumericVector lower = Rcpp::NumericVector::create(1, 0, 1);
    Rcpp::NumericVector upper = Rcpp::NumericVector::create(2, 1, 2);

    Rcpp::NumericVector mean = Rcpp::NumericVector::create(0, 0, 0);
    Rcpp::NumericMatrix cov(3, 3);
    cov(0, 0) = cov(1, 1) = cov(2, 2) = 1;
    return pmvnorm(lower,upper, mean, cov);
}

Best,

Li
On Jan 22, 2015, at 5:44 PM, Yixuan Qiu <yixuan.qiu at cos.name<mailto:yixuan.qiu at cos.name>> wrote:

NumericVector test()
{
    Environment pkg("package:mnormt");
    Function pmnorm = pkg["pmnorm"];
    NumericVector x = NumericVector::create(1, 0, 1);
    NumericVector mean = NumericVector::create(0, 0, 0);
    NumericMatrix cov(3, 3);
    cov(0, 0) = cov(1, 1) = cov(2, 2) = 1;
    return pmnorm(x, mean, cov);
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150123/11a32175/attachment.html>


More information about the Rcpp-devel mailing list