rcpp

Rcpp: Recommended code structure when using data frames with Rcpp (inline)

假装没事ソ 提交于 2019-12-21 20:06:58
问题 [I had this sketched out as a comment elsewhere but decided to create a proper question...] What is currently considered "best practice" in terms of code structuring when using data frames in Rcpp? The ease with which one can "beam over" an input data frame from R to the C++ code is remarkable, but if the data frame has n columns, is the current thinking that this data should be split up into n separate (C++) vectors before being used? The response to my previous question on making use of a

Passing RInside's 'R' instance as a parameter between classes/methods

假如想象 提交于 2019-12-21 19:54:49
问题 I have been using Rcpp and RInside, to integrate R and C++ . We have a complex, yet well designed C++ architecture, and I am finding it difficult to access R from within just 1 function. Is it possible to pass the R instance to different Classes / functions, to get a more OOP design ? If yes, are there any examples ? To elaborate the query, I want to say that something like this, void foo(RInside& R0, int& x0) { R0.assign(x0,"totalSum"); } void foo2(RInside& R0, int& y0) { R0.assign(y0,"temp"

How to resize a NumericVector?

梦想与她 提交于 2019-12-21 03:57:27
问题 How can I resize in Rcpp a NumericVector ? When I use the push_back function for this, the Program slows down. But there are no .resize() or .reserve() functions. (When I have already a NumericVector with the desired size, I can use the copy-constructor to get the correct size of the NumericVector . This is in such a case much faster than usage of push_back ) 回答1: If you prefer the C++ idioms, use std::vector<double> and return that at the end where it will be converted via an implicit wrap()

Error with inline and Xcode 4.2.1

允我心安 提交于 2019-12-21 03:15:08
问题 I'm trying to get the inline package working on my macbook. The following block of code (from the cxxfunction examples) fails: library(inline) fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , ' return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ; ' ) fx( 2L, 5 ) With this error: Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! make: g++-4.2: No such file or directory make: *** [file141b5882.o] Error 1 This

Using `sourceCpp` to compile `fastLm`

末鹿安然 提交于 2019-12-21 02:17:05
问题 I started playing around with Rcpp and would like to use the fastLm function as an example (also because it's useful for potential later work). I know that fastLm is part of the RcppArmadillo package but I would like to compile it using sourceCpp . The code can be found here and is also below. The first problem I encounter is that I can't simply run sourceCpp("fastLm.cpp") in R after installing and loading Rcpp and RcppArmadillo . I get this error error: RcppArmadillo.h: No such file or

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

删除回忆录丶 提交于 2019-12-20 19:08:12
问题 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:

Rcpp Rcpp.package.skeleton(“mypackage”) “rcpp_hello_world” not available for .Call() for package “mypackage”

怎甘沉沦 提交于 2019-12-20 17:35:03
问题 I've managed to get the Rcpp.package.skeleton to INSTALL in Windows by the following commands at the R prompt - Rcpp.package.skeleton("mypackage") system("R CMD build mypackage") system("R CMD INSTALL mypackage") library(mypackage) This creates the mypackage.dll . However when I do the following commands - rcpp_hello_world <- function(){ .Call( "rcpp_hello_world", PACKAGE = "mypackage")} rcpp_hello_world() I get the following error: Error in .Call("rcpp_hello_world", PACKAGE = "mypackage") :

How to generate an R warning safely in Rcpp

守給你的承諾、 提交于 2019-12-20 17:33:13
问题 We know that calling Rf_error() should be avoided in Rcpp as it involves a longjmp over C++ destructors on the stack. This is why we rather throw C++ exceptions in Rcpp code (like throw Rcpp::exception("...") or via the stop("...") function). However, R warnings may also result in a call to Rf_error() (this behavior depends on the warn option). So, a call to Rf_warning() is also risky. Rcpp::sourceCpp(code = ' #include <Rcpp.h> using namespace Rcpp; class Test { public: Test() { Rcout <<

Subset of a Rcpp Matrix that matches a logical statement

假如想象 提交于 2019-12-20 09:53:59
问题 In R, if we have a data matrix, say a 100 by 10 matrix X, and a 100-elements vector t with possible values (0, 1, 2, 3), we can easily find a submatrix y of X using a simple syntax: y = X[t == 1, ] But, the problem is, how can I do that with Rcpp's NumericMatrix ? (Or, more generally, how can I do that in C++'s any containers ?) Thanks to Dirk's hint, it seems that NumericMatrix X(dataX); IntegerVector T(dataT); mat Xmat(X.begin(), X.nrow(), X.ncol(), false); vec tIdx(T.begin(), T.size(),

Rcpp Rtools installed but error message g++ not found

a 夏天 提交于 2019-12-20 09:20:58
问题 I have consulted existing entries on SO related to my specific issue, but still could not resolve it. I am trying to do this with my machine at work, where I have limited admin rights, but I can run Rtools.exe, so I installed it. My setup for R is: platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 version.string R version 3.3.0 (2016-05-03) I am RStudion Version 0.99.902. I installed Rtools version 3.3.0.1959. All of R, Rstudio, and Rtools are installed in C:/WORK/,