rcpp

C++ and R: Create a .so or .dll

巧了我就是萌 提交于 2020-01-02 10:05:54
问题 I have doubt. I know that it is possible to call from a cpp file an R function. But it is possible to compile that cpp file (that has an R function inside -from a package, for example caret -) into a .so or dll ? If it is possible. How does having a chuck of R code inside works. Does the compiled code calls the R interpreter before it compiles or it does not need to? Thanks in advance 回答1: Yes, you can embed R inside of C or C++ application. The API is old, stable, somewhat documented and a

C++ and R: Create a .so or .dll

雨燕双飞 提交于 2020-01-02 10:05:36
问题 I have doubt. I know that it is possible to call from a cpp file an R function. But it is possible to compile that cpp file (that has an R function inside -from a package, for example caret -) into a .so or dll ? If it is possible. How does having a chuck of R code inside works. Does the compiled code calls the R interpreter before it compiles or it does not need to? Thanks in advance 回答1: Yes, you can embed R inside of C or C++ application. The API is old, stable, somewhat documented and a

How to register native routines with Rcpp?

你说的曾经没有我的故事 提交于 2020-01-02 05:34:05
问题 I am writing a Bioconductor package. In order to do that, it needs to pass BiocCheck. I am using Rcpp and Rstudio to make c++ code available to R using the tag //[[Rcpp::export]] and Rcpp classes and not SEXP ones. Rstudio generates Rcpp_export.cpp and Rcpp_export.R automatically and it works fine. However, BiocCheck complains about it: Checking native routine registration.. Register native routines! see http://cran.r-project.org/doc/manuals/R-exts.html#Registering-native-routines So, anybody

Rcpp sugar for rank function

本小妞迷上赌 提交于 2020-01-01 12:23:52
问题 I have been trying to get the rank of a vector in c++ using Rcpp. I have used other sugar functions like is_na(); Is there a similar sugar function for rank R function in c++. Also is there any list of available R sugar functions in Rcpp/ 回答1: 1) There is an order function here and order(order(x)) is rank(x, ties = "first") . 2) A second way would be: match(x, sort(x)) ADDED Second approach. 来源: https://stackoverflow.com/questions/23606266/rcpp-sugar-for-rank-function

Efficiency of matrix rowSums() vs. colSums() in R vs Rcpp vs Armadillo

瘦欲@ 提交于 2020-01-01 08:53:33
问题 Background Coming from R programming, I'm in the process of expanding to compiled code in the form of C/C++ with Rcpp . As a hands on exercise on the effect of loop interchange (and just C/C++ in general), I implemented equivalents to R's rowSums() and colSums() functions for matrices with Rcpp (I know these exist as Rcpp sugar and in Armadillo -- this was just an exercise). Question I have my C++ implementation of rowSums() and colSums() along with Rcpp sugar and arma::sum() versions in this

g++ errors when trying to compile c++11 with Rcpp

时光总嘲笑我的痴心妄想 提交于 2020-01-01 02:35:29
问题 SYSTEM SPEC: OS - Mac OS X 10.6.8 (Snow Leopard) g++ - Macports gcc 4.8.1_2+universal R - 2.15.3 Rcpp - 0.10.3 I keep on receiving an error when I am trying to compile functions that use C++11 in R (through Rcpp) - for some reason, g++ does not recognise -std=c++11 option. This example is taken from Rcpp help files (it does not contain anything specific to C++11, but can show what my problem is). If I try running: require( Rcpp ) Sys.setenv( "PKG_CXXFLAGS"="-std=c++11" ) cppFunction(plugins=c

Fatal error for <RInside.h>

两盒软妹~` 提交于 2019-12-31 06:28:07
问题 I am running this example, through terminal. But got fatal error: RInside.h: No such file or directory error for the the line, #include<RInside.h> . Its a interface to R from c++. I have RInside package in R. my code: #include<iostream> #include<RInside.h> using namespace std; int main(){ int a=12; cout<<a<<endl; return 0; } Same error occurred for #include<Rcpp.h> header. #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] NumericVector callFunction(NumericVector x, Function f) {

Efficiently randomly drawing from a multivariate normal distribution

夙愿已清 提交于 2019-12-30 19:07:40
问题 Just wondering if anyone has ever encountered the problem where he/she needs to randomly draw from a very high dimensional multivariate normal distribution (say dimension = 10,000), as the rmvnorm function of the mvtnorm package is impractical for that. I know this article has an Rcpp implementation for the dmvnorm function of the mvtnorm package, so I was wondering if something equivalent exists for rmvnorm ? 回答1: Here's a quick comparison of mvtnorm::rmvnorm and an Rcpp implementation given

Efficiently randomly drawing from a multivariate normal distribution

断了今生、忘了曾经 提交于 2019-12-30 19:07:26
问题 Just wondering if anyone has ever encountered the problem where he/she needs to randomly draw from a very high dimensional multivariate normal distribution (say dimension = 10,000), as the rmvnorm function of the mvtnorm package is impractical for that. I know this article has an Rcpp implementation for the dmvnorm function of the mvtnorm package, so I was wondering if something equivalent exists for rmvnorm ? 回答1: Here's a quick comparison of mvtnorm::rmvnorm and an Rcpp implementation given

function pass by reference in RcppArmadillo

邮差的信 提交于 2019-12-30 07:29:10
问题 I have a function written in RcppArmadillo style and I want to use it for changing variables in the calling environment. I know it is not advisable to do things like this, but it's helpful in my case. Concretely, I'm trying this: #include <RcppArmadillo.h> #include <iostream> //[[Rcpp::export]] void myfun(double &x){ arma::mat X = arma::randu<arma::mat>(5,5); arma::mat Y = X.t()*X; arma::mat R1 = chol(Y); x = arma::det(R1); std::cout << "Inside myfun: x = " << x << std::endl; } /*** R x = 1.0