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
14
votes
1 answer

How to handle list in R to Rcpp

I have a list in R that x<-list(c(1,2,3), c(4,5), c(5,5), c(6)). I want to input the list to Rcpp and return them as an average vector, c(2, 4.5, 5, 6). I am not sure how to handle the list in Rcpp. I got an error message, so could someone check my…
user1690124
  • 303
  • 1
  • 2
  • 7
14
votes
3 answers

returning a custom object from a wrapped method in Rcpp

I have the following problem with the Rcpp module: let's assume I've two classes in a Rcpp module class A { public: int x; }; class B public: A get_an_a(){ A an_a(); an_a.x=3; return an_a; } }; RCPP_MODULE(mod){ …
Thomas Handorf
  • 371
  • 5
  • 11
14
votes
2 answers

Fast bounding of data in R

Suppose I have a vector, vec, which is long (starting at 1E8 entries) and would like to bound it to the range [a,b]. I can certainly code vec[vec < a] = a and vec[vec > b] = b, but this requires two passes over the data and a large RAM allocation…
Iterator
  • 20,250
  • 12
  • 75
  • 111
13
votes
1 answer

information on .o files for x64 is not available: NOTE on R package checks using Rcpp

I am using windows and just updated to R 4.0.3 (with RStudio to 1.3.959) and ran the R check for one of my packages which uses Rcpp and RcppArmadillo and I got the following NOTE: > checking compiled code ... NOTE Note: information on .o files for…
13
votes
2 answers

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

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++…
Solomon
  • 946
  • 14
  • 18
13
votes
4 answers

Editing array to ensure strictly increasing values

Consider a sorted vector x that is bounded between min and max. Below is an example of such x where min could be 0 and max could be 12: x = c(0.012, 1, exp(1), exp(1)+1e-55, exp(1)+1e-10, exp(1)+1e-3, 3.3, 3.33333, 3.333333333333333, 3+1/3,…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
13
votes
1 answer

efficiently locf by groups in a single R data.table

I have a large, wide data.table (20m rows) keyed by a person ID but with lots of columns (~150) that have lots of null values. Each column is a recorded state / attribute that I wish to carry forward for each person. Each person may have anywhere…
carl.anderson
  • 1,040
  • 11
  • 16
13
votes
2 answers

Rcpp and default C++ compiler

I have some strange troubles with Rcpp - it uses unpredictable C++ compiler. This question is somewhat similar to this question. I'm on OSX, I have 2 complilers - default clang and clang-omp with openmp support. Also I have following ~/.R/Makevars…
Dmitriy Selivanov
  • 4,545
  • 1
  • 22
  • 38
13
votes
3 answers

Return RcppArmadillo vector as R vector

I having trouble figuring out how to return an RcppArmadillo colvec as a standard R vector. I was hoping I could typecast through as(wrap()) but I still end up with objects that are R matrices. Here's a bit of code to show what I've…
ekstroem
  • 5,957
  • 3
  • 22
  • 48
13
votes
1 answer

Fastest way to compute the cdf of the Normal distribution over vectors - R::pnorm vs erfc vs?

I hope my reworded question now fits the criteria of Stackoverflow. Please consider the example below. I am writing a Log-Likelihood function in which computing the cdf over vectors is the most time consuming part. Example 1 uses the R::pnorm,…
chameau13
  • 626
  • 7
  • 24
13
votes
2 answers

Rcpp warning: "directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'"

This question relates to some others out there, like RccpArmadillo or element-wise-multiplication. However, my settings are such that I do not know what I have to edit/simlink to make Rccp run without giving me warnings. I am on an Mac 10.9…
Javier
  • 1,530
  • 4
  • 21
  • 48
13
votes
1 answer

Calling a Rcpp function from another Rcpp function while building an R package

I took this example from a different question. I am building an R package with Rcpp. I have a function like fun1 (below) that I want to put into its own .cpp file. Then I want to call fun1 with other functions (like fun() does below). I want fun1…
user3583481
  • 133
  • 1
  • 5
13
votes
3 answers

How to build a R package which use Rcpp with external c++ libraries?

Such as boost, where can I specify the following: 1.External c++ header file include path 2.External c++ source file 3.External c++ link library file path
Xiaobo Gu
  • 199
  • 1
  • 10
12
votes
2 answers

Rcpp and int64 NA value

How can I pass an NA value from Rcpp to R in a 64 bit vector? My first approach would be: // [[Rcpp::export]] Rcpp::NumericVector foo() { Rcpp::NumericVector res(2); int64_t val = 1234567890123456789; …
David
  • 9,216
  • 4
  • 45
  • 78
12
votes
1 answer

Arithmetic in R faster on numerics as opposed to integers. What's going on?

I was in the middle of converting some code that utilized mostly numeric data (i.e. doubles) to integers and did a quick benchmark to see how much efficiency I gained. To my surprise it was slower... by about 20%. I thought I had done something…
Joseph Wood
  • 7,077
  • 2
  • 30
  • 65