[Rcpp-devel] dmvnorm() of mvtnorm using RcppArmadillo

Shaami nzshaam at gmail.com
Thu Dec 19 05:26:08 CET 2019


Hi Dear

I want to use dmvnorm() function into an cpp function using RcppArmadillo I
am trying to execute the following function. It gives me error

cannot convert 'SEXP' to 'double' in assignment

Could you please guide where I am wrong?

#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace RcppArmadillo;
using namespace arma;

//[[Rcpp::depends(RcppArmadillo)]]
//[[Rcpp::export]]

arma::rowvec  dmvnormC(const arma::mat& x, const arma::vec& mean, const
arma::mat& sigma, int give_log)
{
  Environment pkg = Environment::namespace_env("mvtnorm");
  Function dmvnorm = pkg["mvtnorm"];
  int N = x.n_rows;
  arma::rowvec f(N, fill::zeros);
  for(int k=0; k<N; k++)
    {
      f(k) = dmvnorm(x.row(k), mean,  sigma, give_log);
    }
  return f;
}

Thank you

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


More information about the Rcpp-devel mailing list