[Rcpp-devel] rgamma() behavior
Gregor Kastner
gregor.kastner at wu.ac.at
Tue Mar 25 00:34:15 CET 2014
Dear all,
I believe it's the second time I just realized that Rcpp::rgamma() behaves
differently than to R's rgamma() when called without named arguments:
********** BEGIN code.R **********
library(Rcpp)
cppFunction('
SEXP rgamma2(const int n, const double a, const double b) {
RNGScope scope;
return Rcpp::rgamma(n, a, b);
}
')
set.seed(123);
print(rgamma(1, 2, 3));
set.seed(123);
print(rgamma2(1L, 2, 3));
set.seed(123);
print(rgamma2(1L, 2, 1/3));
********** END code.R **********
yields:
[1] 0.2973645
[1] 2.676281
[1] 0.2973645
Maybe this is worth a tiny note in e.g. the "Rcpp syntactic sugar" vignette?
Might save me (and possibly others) from realizing a third time.
Best and thanks,
Gregor
More information about the Rcpp-devel
mailing list