rcpp

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

[亡魂溺海] 提交于 2019-12-03 06:16:59
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("cpp11"), ' int useCpp11() { int x = 10; return x; }') I get: cc1plus: error: unrecognized command

How can I pass flags to R when it is compiling C++ code to be used in a package?

纵然是瞬间 提交于 2019-12-03 05:59:36
I am trying to use some code from OpenCV in an R package, using Rcpp to build the package. When I compile the c code on my machine, it works fine. For example, I am using the the following syntax locally to compile the facedetect.cpp code: g++ `pkg-config --cflags opencv` facedetect.cpp -o facedetect `pkg-config --libs opencv` However, when I try to include it in my package using the following command: R CMD SHLIB facedetect.cpp -o facedetect with the following defined in my makevars file: PKG_CPPFLAGS= `$(R_HOME)/bin/Rscript -e 'Rcpp:::CxxFlags()'` PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp::

Within C++ functions, how are Rcpp objects passed to other functions (by reference or by copy)?

落花浮王杯 提交于 2019-12-03 04:30:54
问题 I've just finished writing a new version of the ABCoptim package using Rcpp. With around 30x speed ups, I'm very happy with the new version's performance (vs old version), but I'm still having some concerns on if I have space to improve performance without modifying too much the code. Within the main function of ABCoptim (written in C++) I'm passing around a Rcpp::List object containing "bees positions" (NumericMatrix) and some NumericVectors with important information for the algorithm

Best way to use c++ code from R package FOO in package BAR

泪湿孤枕 提交于 2019-12-03 03:01:40
I am trying to define a function using Rcpp for speedup. The situation is as follows: I have a package FOO with a lot of C++ code (my own package and currently not using Rcpp) which have defined a set of functions e.g. foo_a and foo_b. In another package BAR (using Rcpp) I am defining a function (using Rcpp Attributes) where I want to call functions foo_a and foo_b. How do I solve this? Looking a bit in other posts I get that I have in some way to include header files in FOO and use attribute // [[Rcpp::depends(FOO)]] in BAR, but I seem to miss some points. Any hints on how to do it? Best Lars

Running compiled C++ code with Rcpp

天涯浪子 提交于 2019-12-03 03:00:15
I have been working my way through Dirk Eddelbuettel's Rcpp tutorial here: http://www.rinfinance.com/agenda/ I have learned how to save a C++ file in a directory and call it and run it from within R. The C++ file I am running is called 'logabs2.ccp' and its contents are directly from one of Dirk's slides: #include <Rcpp.h> using namespace Rcpp; inline double f(double x) { return ::log(::fabs(x)); } // [[Rcpp::export]] std::vector<double> logabs2(std::vector<double> x) { std::transform(x.begin(), x.end(), x.begin(), f); return x; } I run it with this R code: library(Rcpp) sourceCpp("c:/users

Rcpp matrix: loop over rows, one column at a time

99封情书 提交于 2019-12-03 02:46:34
问题 This is my first time trying Rcpp and this very simple problem is giving me trouble. I want to use nested for loops to operate on individual values of a matrix, one column at a time. The script I'm aiming for would look something like this: src <- ' Rcpp::NumericMatrix Am(A); int nrows = Am.nrow(); int ncolumns = Am.ncol(); for (int i = 0; i < ncolumns; i++){ for (int j = 1; j < nrows; j++){ Am[j,i] = Am[j,i] + Am[j-1,i]; } } return Am; ' fun <- cxxfunction(signature(A = "numeric"), body =

Deciding between NumericVector and arma::vec in Rcpp

老子叫甜甜 提交于 2019-12-03 00:23:27
With RcppArmadillo the conversion from R to Rcpp with arma::vec is just as easy as with Rcpp and NumericVector . My project utilizes RcppArmadillo. I'm unsure what to use, NumericVector or arma::vec ? What are the key differences between those two? When to use which? Is there a performance/memory advantage of using one over the other? Are the only difference the member functions? And, as a bonus question: should I even consider arma::colvec or arma::rowvec ? What are the key differences between those two? The *Vector and *Matrix classes in Rcpp act as wrappers for R 's SEXP representation, e.g

constructing a Data Frame in Rcpp

空扰寡人 提交于 2019-12-03 00:11:44
I want to construct a data frame in an Rcpp function, but when I get it, it doesn't really look like a data frame. I've tried pushing vectors etc. but it leads to the same thing. Consider: RcppExport SEXP makeDataFrame(SEXP in) { Rcpp::DataFrame dfin(in); Rcpp::DataFrame dfout; for (int i=0;i<dfin.length();i++) { dfout.push_back(dfin(i)); } return dfout; } in R: > .Call("makeDataFrame",mtcars,"myPkg") [[1]] [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 [31] 15.0 21.4 [[2]] [1] 6 6 4

Speed up the loop operation in R

霸气de小男生 提交于 2019-12-02 23:54:28
问题 I have a big performance problem in R. I wrote a function that iterates over a data.frame object. It simply adds a new column to a data.frame and accumulates something. (simple operation). The data.frame has roughly 850K rows. My PC is still working (about 10h now) and I have no idea about the runtime. dayloop2 <- function(temp){ for (i in 1:nrow(temp)){ temp[i,10] <- i if (i > 1) { if ((temp[i,6] == temp[i-1,6]) & (temp[i,3] == temp[i-1,3])) { temp[i,10] <- temp[i,9] + temp[i-1,10] } else {

Update Rcpp::NumericMatrix passed by reference using RcppArmadillo submat()

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 22:00:01
问题 Following on this question, I am trying to understand how to efficiently update a subset of a Rccp::NumericMatrix data type. I have the following scenario: Rcpp::NumericMatrix m of 5 x 5 that needs few rows and columns updated. It will be passed by reference to a function ( void return type) that will convert it to an arma::mat , and update the respective submat() . At this point I don't understand how to " apply " the changes that occurred inside the function to the m matrix that was passed