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

Shaami nzshaam at gmail.com
Thu Dec 19 07:57:44 CET 2019


Dear Sir

It compiles successfully. But when I use it I get an error message.



On Thu, Dec 19, 2019 at 7:41 PM Shaami <nzshaam at gmail.com> wrote:

> Great. It worked.
>
> Thank you very much
>
> On Thu, 19 Dec 2019, 6:01 PM Qiang Kou, <qkou at qkou.info> wrote:
>
>> Please try the line below:
>>
>> f(k) = *Rcpp::as<double>*(dmvnorm(x.row(k), mean,  sigma, give_log));
>>
>> Best,
>>
>> KK
>>
>> On Wed, Dec 18, 2019 at 8:27 PM Shaami <nzshaam at gmail.com> wrote:
>>
>>> 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
>>> _______________________________________________
>>> Rcpp-devel mailing list
>>> Rcpp-devel at lists.r-forge.r-project.org
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20191219/503e054f/attachment.html>


More information about the Rcpp-devel mailing list