Questions tagged [rcpp]

Rcpp provides seamless integration of C++ code in R.

Rcpp is an package allowing integration with code. R data types (SEXP) are matched to C++ objects in a class hierarchy. All R types are supported and each type is mapped to a dedicated class.

Repositories

Vignettes

Books

Other resources

Related tags

3011 questions
1
vote
1 answer

Simulation of AR(1) in Rcpp

Is there a way of calling arima.sim using Rcpp sugar? The fact that it need an R list as an argument has been my biggest stumbling block so far. I've got it to work by using a global definition as below, but would much prefer if I could contain it…
John Siryj
  • 39
  • 1
  • 8
1
vote
1 answer

Filling multidimensional matrix from file is slow on Windows

I wrote a C++ (Rcpp) function to read and fill a multidimensional matrix from a file containing only numbers. When I run it on Linux it works fine and it is pretty fast. However, the same code is much slower (by a factor of 200) on a Windows machine…
Philippe Massicotte
  • 1,321
  • 12
  • 24
1
vote
0 answers

Fastest way to compute Gaussian kernel vector in CppArmadillo?

I am trying to compute a vector of gaussian kernel evaluations as quickly as possible. I have a data point x in R^p, and a matrix X of n vectors x_i. I would like to compute exp( -||x-x_i||^2 / t) for every x_i and return the result as a vector. I…
1
vote
1 answer

Getting r function args from Rcpp c++ function

I have defined a function on the R-side like this: foo <- function(arg1, arg2, arg3) { ... } and a function in c++ using Rcpp that gets the global environment and instantiates the R function to execute it from that function. Here is the…
bra_racing
  • 622
  • 1
  • 8
  • 32
1
vote
1 answer

Rcpp eig_sym and R's eigen don't deliver the same result

I am currently encountering problems regarding the computation of eigenvalues with Rcpp. When using Rcpp's eig_sym I don't get the same result as with R's eigen, although it is stated at the web page of Armadillo that it ought to deliver the same…
Louki
  • 215
  • 1
  • 12
1
vote
1 answer

Generating a random bit stream in Rcpp efficiently

I have an auxiliary function in the R package I'm currently building named rbinom01. Note that it calls random(3). int rbinom01(int size) { if (!size) { return 0; } int64_t result = 0; while (size >= 32) { result +=…
nalzok
  • 14,965
  • 21
  • 72
  • 139
1
vote
0 answers

C++ equivalent to R's set.seed() function

I would like to do the equivalent of R's set.seed() inside of a C++ function. How do I do this? Note that I make this C++ function available in R via the Rcpp package. I would like myfun(seed=42) to return the same result each time it is called in…
DanY
  • 5,920
  • 1
  • 13
  • 33
1
vote
1 answer

Checking non-finite values in Rcpp without creating a vector

I haven written Rcpp code to perform a calculation related to time series: #include // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::export]] double AmiA(arma::vec ts, int n, double cf, double h, double g) { double sumA =…
gultu
  • 143
  • 10
1
vote
1 answer

Undefined reference when building R package using Rcpp with an external C++ library

I'm trying to create a R package for my own use, that is using Rcpp and whose C++ code include the Levmar library. I'm working on Windows. The C++ code works fine when I build it using CMake for example and run it with Visual Studio. But when I put…
Herrvey
  • 23
  • 1
  • 3
1
vote
1 answer

Insert submatrix with Rcpp

I am trying to achieve the following R example with Rcpp: X <- matrix(0, 5, 10) X[1:4, 4] <- rexp(4) What I have tried so far is: #include using namespace Rcpp; // [[Rcpp::export]] NumericMatrix foo1() { NumericMatrix X(5, 10); …
johannes
  • 14,043
  • 5
  • 40
  • 51
1
vote
3 answers

How to avoid reading data from R environment within Rcpp function

Even though MyCppFunction(NumericVector x) returns the desired output, I am not sure of a proper/efficient way to avoid reading the data on variable myY withou passing it as a function argument. The reason I do not pass the data as an argument is…
NewUser
  • 336
  • 2
  • 10
1
vote
3 answers

Rcpp max of vector except one element

In Rcpp I want to find the maximum of a vector, but I want to omit one element. I have working code, but I'm sure my approach is quite bad as it involves the full copy of the vector. Is there a much better way to accomplish what I want? In…
DanY
  • 5,920
  • 1
  • 13
  • 33
1
vote
0 answers

Setting custom R class names instead of Rcpp_ + class-name with RCpp modules

I have developed a package for R using Rcpp modules. If I understand correctly, when I export a C++ class using the RCPP_EXPOSED_CLASS macro, an R class named Rcpp_[class-name] is created, and this can be used to define S3 methods as in…
1
vote
1 answer

Swap two SEXP without copying

Using SEXP as argument of a function don't allows user to exchange data between them by simple assignement. I used to copy each value with a tmp buffer to perform swapping. My question is :there is a possibilty to write a function that only swap…
MACHERKI M E
  • 131
  • 9
1
vote
0 answers

Rcpp vs normal C++: header flag available?

I'm a beginner at Rcpp (though with a bit of experience in both R and C++) and am trying to write some code that can be used in both Rcpp and native C++. As such, I am writing some wrapper functions that return data frames, numeric vectors and the…
Harvey Ellis
  • 596
  • 1
  • 3
  • 12
1 2 3
99
100