rcpp

R package with both .c and .cpp files with Rcpp

五迷三道 提交于 2019-12-22 12:56:05
问题 I'm trying to build an R package which contains both C (in the form of .c files) and C++ code (in the form of .cpp files) using the Rcpp package as a dependency. I have a couple of questions. First, is it actually possible to do this? Can one call C scripts and C++ scripts that are in the same R package? If the previous is possible, how then does one properly register the functions in the C and C++ scripts. To help with this, I have set up a little example which is available on my GitHub page

Rcpp quantile implementation

让人想犯罪 __ 提交于 2019-12-22 10:31:18
问题 I have a Rcpp double containing a NumericVector x. I would like to get the .95 quantile of such x within the Rcpp code flow. I do not know how can I get it. Is there an RcppArmadillo implementation? 回答1: I'm not a Rcpp expert and my function probably needs lots of improvement, but it seems that you can easily create your own Rcpp quantile function (which will be not so accurate on small vectors due to high chance to skewness and problems with indexing on non-integer indexes, but improves as

Converting between NumericVector/Matrix and VectorXd/MatrixXd in Rcpp(Eigen) to perform Cholesky solve

时光怂恿深爱的人放手 提交于 2019-12-22 09:36:23
问题 Edit : with some clues from Dirk's answer below I worked this out, solution in the body of the question now. I'm sure this must be documented somewhere but my google skills are failing me. I'm developing an Rcpp package where I didn't think I would need dependency on Eigen, so I used NumericVector/Matrix quite extensively. However, I now need a Cholesky decomp/solve: I know how to do this using RcppEigen but I need VectorXd/MatrixXd 's. Say I have a P.S.D. NumericMatrix, A, and a

Rcpp and move semantic

被刻印的时光 ゝ 提交于 2019-12-22 08:18:06
问题 I implemented an algorithm in C++ that returns as output a huge array of elements. Now, I would like to implement a wrapper in Rcpp so that I will be able to call this function by using R . I specified in the Makevars file the following setting: PKG_CXXFLAGS = -std=c++11 So that I can use the C++11 version. // [[Rcpp::export]] NumericMatrix compute(int width, int height) { vector<data_t> weights(width * height); compute_weights(weights); NumericMatrix mat(height, width); copy(begin(weights),

Installing R `forecast` package on a Linux Cluster: compiler issues?

南楼画角 提交于 2019-12-22 05:53:11
问题 I am looking to test performance of R , more specifically some routines in the forecast package on an HPC cluster with Intel Xeon Phi co-processors. The sysadmin has, I understand, built R/3.2.5 from source following the instructions on Intel's website: https://software.intel.com/en-us/articles/build-r-301-with-intel-c-compiler-and-intel-mkl-on-linux So R works, installation of packages including devtools , data.table , dplyr , ggplot2 , Rcpp , RcppArmadillo can be carried out from within an

Installing R `forecast` package on a Linux Cluster: compiler issues?

天涯浪子 提交于 2019-12-22 05:53:08
问题 I am looking to test performance of R , more specifically some routines in the forecast package on an HPC cluster with Intel Xeon Phi co-processors. The sysadmin has, I understand, built R/3.2.5 from source following the instructions on Intel's website: https://software.intel.com/en-us/articles/build-r-301-with-intel-c-compiler-and-intel-mkl-on-linux So R works, installation of packages including devtools , data.table , dplyr , ggplot2 , Rcpp , RcppArmadillo can be carried out from within an

Read variables from global environment with inline Rcpp?

寵の児 提交于 2019-12-22 05:13:09
问题 I'm following the example from the Rcpp intro Vignette, trying it with inline. f<-cxxfunction(signature(), plugin="Rcpp", body=" Environment global = Environment::global_env(); std::vector<double> vx = global['x']; ") but I get a compile error. file12384509.cpp: In function 'SEXPREC* file12384509()': file12384509.cpp:31: error: invalid use of incomplete type 'struct SEXPREC' C:/PROGRA~1/R/R-211~1.1/include/Rinternals.h:333: error: forward declaration of 'struct SEXPREC' file12384509.cpp:31:

How to determine the class of object stored in SEXP in Rcpp? [duplicate]

喜夏-厌秋 提交于 2019-12-22 00:39:46
问题 This question already has answers here : Initialize a variable with different type based on a switch statement (2 answers) Closed 3 years ago . //[[Rcpp::export]] int Class_data(SEXP data) { /* return 0 if class of data is matrix else return -1 */ } How to determine the class of data in the above case? If data belongs to matrix class return 0 else return -1. 回答1: Depending on what type of object you are checking for, there may be a predefined Rf_isWhatever macro, or you may need to use the Rf

Rcpp: rearrange a vector in an order of another vector

无人久伴 提交于 2019-12-22 00:17:25
问题 I am new in Rcpp. I need to rearrange a vector A in an order of another vector B ; For example, A=c(0.5,0.4,0.2,0.9) B=c(9,1,3,5) I want to make C=c(0.4,0.2,0.9,0.5) by Rcpp. I know the simple r code, C=A[order(B)] , but it is necessary for me to use Rcpp code. I found how to find the order of B by using sort_index , but I fail to arrange A with respect to an order of B . How can I make it? 回答1: You should be able to use arma::sort_index for this, which you mention in your post: #include

Creating a std::shared_ptr object and returning it to the R side (Rcpp)

ぃ、小莉子 提交于 2019-12-21 21:13:13
问题 I'm trying to write a R bindings for a C++ script using Rcpp. One of the functions expects a std::shared_ptr object . I find it difficult to initialize the std::shared_ptr obj and return it to the R side as a Rcpp::XPtr object. I've tried (minimal example): #include <iostream> #include <memory> #include <Rcpp.h> using namespace Rcpp; using std::cout; class TestClass { public: int value; TestClass(int initial_val) { value = initial_val; }; }; //[[Rcpp::export]] SEXP get_test_obj() { Rcpp::XPtr