Hi Sir Could you please help for the following error message.
Below is the minimum working example and error I got. y <- matrix(1:10, nrow=5) mean <- c(4, 5) sigma <- matrix(c(0.01, 0.009, 0.009, 1.2), nrow =2, byrow = TRUE) dmvnormC(y, mean, sigma, 0) # Function is below. Error in dmvnormC(y, mean, sig, 0) : Cannot convert object to a function: [type=NULL; target=CLOSXP, SPECIALSXP, or BUILTINSXP]. #include <RcppArmadillo.h> using namespace Rcpp; using namespace RcppArmadillo; using namespace arma; //[[Rcpp::depends(RcppArmadillo)]] //[[Rcpp::export]] arma::vec 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) = Rcpp::as<double>(dmvnorm(x.row(k), mean, sigma, give_log)); } return f; } Thank You On Thu, Dec 19, 2019 at 7:57 PM Shaami <nzsh...@gmail.com> wrote: > 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 <nzsh...@gmail.com> wrote: > >> Great. It worked. >> >> Thank you very much >> >> On Thu, 19 Dec 2019, 6:01 PM Qiang Kou, <q...@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 <nzsh...@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@lists.r-forge.r-project.org >>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >>> >>>
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel