Re: [Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Dirk Eddelbuettel
Eridk, See these Rcpp Gallery article from 2012 for worked examples: - http://gallery.rcpp.org/articles/using-rmath-functions/ has an example on pnorm that applies to your dnorm case - http://gallery.rcpp.org/articles/random-number-generation/ discusses the RNGs, but the d/p/q

Re: [Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Romain Francois
Hello, Functions in sugar only apply to vectors. For a single value, you’d have to use the dnorm function in the R:: namespace: // [[Rcpp::export]] double test6(double x){ double y = R::dnorm(x,5.0,2.0,true); return y; } > test6(3) [1] -2.112086 > dnorm(3, mean = 5, sd = 2, log = TRUE)

[Rcpp-devel] Rcpp sugar for double?

2017-02-22 Thread Eridk Poliruyt
Hi, I just tried to calculate the density of a normal variable using dnorm. I found that if the input is of type NumericVector, then it was fine. But if the input is of type double, it yielded error in compilation. For example: // [[Rcpp::export]] NumericVector test5(NumericVector x) { NumericV