# NOT RUN {
# default plugin
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"return 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<int>(x) * as<double>(y));",
plugin = "Rcpp" )
fx(2L, 5)
## equivalent shorter form using rcpp()
fx <- rcpp(signature(x = "integer", y = "numeric"),
"return wrap(as<int>(x) * as<double>(y));")
}
# RcppArmadillo plugin
if (requireNamespace(RcppArmadillo)) {
fx <- cxxfunction(signature(x = "integer", y = "numeric"),
"int dim = as<int>(x);
arma::mat z = as<double>(y) * arma::eye<arma::mat>(dim, dim);
return wrap(arma::accu(z));",
plugin = "RcppArmadillo")
fx(2L, 5)
}
# }
Run the code above in your browser using DataLab