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
12
votes
2 answers

Converting an Armadillo Matrix to an Eigen MatriXd and vice versa

How can I convert from an Armadillo Matrix to an Eigen MatrixXd and vice versa? I have nu as an arma::vec of size N, z as arma::mat of dimension N x 3. I want to compute a matrix P such as the entry P_ij is Pij=exp(nu(i) + nu(j) +…
Ari.stat
  • 463
  • 4
  • 13
12
votes
1 answer

Default NULL parameter Rcpp

I am trying to define a function with a default NULL parameter in Rcpp. Following is an example: // [[Rcpp::export]] int test(int a, IntegerVector kfolds = R_NilValue) { if (Rf_isNull(kfolds)) { cout << "NULL" << endl; } else { …
Nick
  • 10,309
  • 21
  • 97
  • 201
12
votes
2 answers

Building a tiny R package with CUDA and Rcpp

I'm working on a tiny R package that uses CUDA and Rcpp, adapted from the output of Rcpp.package.skeleton(). I will first describe what happens on the master branch for the commit entitled "fixed namespace". The package installs successfully if I…
landau
  • 5,636
  • 1
  • 22
  • 50
12
votes
2 answers

Exceeded maximum number of DLLs in R

I am using RStan to sample from a large number of Gaussian Processes (GPs), i.e., using the function stan(). For every GP that I fit, another DLL gets loaded, as can be seen by running the R command getLoadedDLLs() The problem I'm running into is…
Doug Jackson
  • 131
  • 2
  • 7
12
votes
1 answer

Row limit for data.table in R using fread

I wanted to know if there is a limit to the number of rows that can be read using the data.table fread function. I am working with a table with 4 billion rows, 4 columns, about 40 GB. It appears that fread will read only the first ~ 840 million…
xbsd
  • 2,438
  • 4
  • 25
  • 35
12
votes
2 answers

Passing by reference a data.frame and updating it with rcpp

looking at the rcpp documentation and Rcpp::DataFrame in the gallery I realized that I didn't know how to modify a DataFrame by reference. Googling a bit I found this post on SO and this post on the archive. There is nothing obvious so I suspect I…
statquant
  • 13,672
  • 21
  • 91
  • 162
12
votes
2 answers

Constructing 3D array in Rcpp

I am trying to map a 1D array onto 3D array using provided list of dimensions. Here are my components: SEXP data; // my 1D array // I can initialise new 3D vector in the following way: NumericVector vector(Dimension(2, 2, 2); // or the…
Datageek
  • 25,977
  • 6
  • 66
  • 70
11
votes
1 answer

Proper way to return a pointer to a `new` object from an Rcpp function

Consider 1) a custom class with a potentially large memory print, and 2) a top-level function that performs some pre-processing, then creates and returns a new object of our custom class. To avoid unnecessary copying by value, the function allocates…
Artem Sokolov
  • 13,196
  • 4
  • 43
  • 74
11
votes
0 answers

Rcpp::String keep UTF-8 encoding, but std::string does not

How do I interact with code that builds a vector of strings with std::vector and maintain UTF-8 encoding in the same way that Rcpp::String does by default? I have a std::vector of UTF-8 strings that I want to be able to…
knapply
  • 647
  • 1
  • 5
  • 11
11
votes
1 answer

Read binary files in R from a zipped file and a known starting position (byte offset)

I have a zipped binary file under the Windows operating system that I am trying to read with R. So far it works using the unz() function in combination with the readBin() function. > bin.con <- unz(zip_path, file_in_zip, open = 'rb') >…
takje
  • 2,630
  • 28
  • 47
11
votes
2 answers

R package with C/C++ and openMP: how to make "Makevars" file under "mypackage/src/" folder?

I am developing an R package on Mac OSX with some low level C/C++ code and openMP support. The C++ code is written using Rcpp package. My global ''Makevars'' file is placed under ~/.R/ folder. The file looks like…
SixSigma
  • 2,808
  • 2
  • 18
  • 21
11
votes
1 answer

Can Rcpp expose a C++ class method taking a reference to the same class?

Is it possible to use Rcpp to expose a C++ class to R when the class has a member taking an instance of that class? Example: #include class Test { public: Test(int x): x_(x) {} int getValue() { return x_; } void addValue(int y)…
Grisby_2133
  • 487
  • 2
  • 11
11
votes
1 answer

List of Rcpp sugar functions?

I'm just getting started with Rcpp and wondering if somewhere out there a list of Rcpp sugar functions exists. In the process of translating some of my slow code to C/C++ I'll need functionality provided by base R functions like match, tabulate,…
Zoë Clark
  • 1,334
  • 2
  • 13
  • 25
11
votes
1 answer

Rcpp function crashes

My problem: I am using R.3.0.1 together with RStudio 0.97.551 on a 64bit Windows7 PC and I have begun to outsource a function to C/C++ using Rcpp. The function compiles, but evaluating it within an R function produces a runtime error. I am not able…
pfifas
  • 592
  • 4
  • 11
11
votes
4 answers

Link error installing Rcpp "library not found for -lintl"

I just stumbled over a linker error when trying to install some R packages which have Rcpp as a dependency. My setup is Mac OS X 10.9.1 (Mavericks), R 3.0.2 installed by Homebrew. Here's the error output: > install.packages('Rcpp') trying URL…
cbare
  • 12,060
  • 8
  • 56
  • 63