if (FALSE) {
# default plugin
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return Rf_ScalarReal(INTEGER(x)[0] * REAL(y)[0]);")
fx(2L, 5)
# Rcpp plugin
if (requireNamespace("Rcpp", quietly=TRUE)) {
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return wrap( as(x) * as(y));",
plugin = "Rcpp" )
fx(2L, 5)
## equivalent shorter form using rcpp()
fx <- rcpp(signature(x = "integer", y = "numeric"),
"return wrap(as(x) * as(y));")
}
# RcppArmadillo plugin
if (requireNamespace(RcppArmadillo)) {
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"int dim = as(x);
arma::mat z = as(y) * arma::eye(dim, dim);
return wrap(arma::accu(z));",
plugin = "RcppArmadillo")
fx(2L, 5)
}
}
Run the code above in your browser using DataLab