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

Overriding system defaults for C++ compilation flags from R

I'm using RcppEigen to write some C++ functions for my R code, and I'd like to optimize their compilation as much as possible. When I've used Eigen in the past, I've gotten a significant boost from -O3 and -fopenmp. Following Dirk's advice, I edited…
stackoverflax
  • 1,077
  • 3
  • 11
  • 25
11
votes
2 answers

How use correctly Rcpp::pt( )

I am reading the chapter 4 of "Seamless R and C++ Integration with Rcpp" and I had a little problem. In the "listing 4.13" the book given a example about how to use a function of R. I tried use other functions (different of the example) and I had…
carlos1985
  • 318
  • 1
  • 9
11
votes
3 answers

Running compiled C++ code with Rcpp

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…
Mark Miller
  • 12,483
  • 23
  • 78
  • 132
11
votes
1 answer

Rcpp: Save compiled function as Robj

If I define a function in R, I can save the function object using the save function. Then I can load that function object using the load function and use it directly. However, if I have a rcpp function, and if I try to save the compiled version and…
Chris
  • 589
  • 4
  • 11
11
votes
1 answer

Rcpp - Use multiple C++ functions in file referenced by sourceCpp?

I hope this isn't too obvious, as I've searched all day and can't find the answer. Say I have the following R file: library(Rcpp) sourceCpp("cfile.cpp") giveOutput(c(1,2,3)) And it compiles the following C++ file: #include using namespace…
Patrick McCarthy
  • 2,478
  • 2
  • 24
  • 40
11
votes
4 answers

Passing a `data.table` to c++ functions using `Rcpp` and/or `RcppArmadillo`

Is there a way to pass a data.table objects to c++ functions using Rcpp and/or RcppArmadillo without manually transforming to data.table to a data.frame? In the example below test_rcpp(X2) and test_arma(X2) both fail with c++ exception (unknown…
user2503795
  • 4,035
  • 2
  • 34
  • 49
10
votes
1 answer

How to set g++ compiler flags using Rcpp and inline?

I want to set -std=c++0x, using Rcpp with inline. I saw R: C++ Optimization flag when using the inline package but don't want to make a system-wide change, so I was trying option 2 in Dirk's answer. I…
Darren Cook
  • 27,837
  • 13
  • 117
  • 217
10
votes
1 answer

RcppArmadillo's sample() is ambiguous after updating R

I commonly work with a short Rcpp function that takes as input a matrix where each row contains K probabilities that sum to 1. The function then randomly samples for each row an integer between 1 and K corresponding to the provided probabilities.…
yrx1702
  • 1,619
  • 15
  • 27
10
votes
1 answer

Pass a c++ object as a pointer an reuse in another function in Rcpp

Suppose a I have the following 2 functions in C++: // [[Rcpp::export]] SEXP foo() { int a = 1; Rcpp::XPtr ptr(&a, true); return ptr; } // [[Rcpp::export]] int bar(SEXP a){ Rcpp::XPtr x(a); int b = *x; return b; } I want…
Daniel Falbel
  • 1,721
  • 1
  • 21
  • 41
10
votes
2 answers

Using an alternate compiler for Travis-CI R project builds

Travis-CI's official R project build support on Ubuntu uses (at the time of this question) gcc version 4.6. CRAN uses gcc 4.9 and some packages that build fine on CRAN will not build on Travis with gcc 4.6. How does one change the default gcc…
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
10
votes
1 answer

Manipulating NumericMatrix in Rcpp

I'm new with Rcpp. I have read Advanced R by Hadley Wickham and all Rcpp vignettes but i can't figure how to manipulate NumericMatrix objects. Is there any simple way to do things like this R code mat <- matrix(1:9,3,3) v <- matrix(2,2,2) mat[1,] <-…
throwic
  • 153
  • 1
  • 8
10
votes
2 answers

Rcpp NumericMatrix - how to erase a row / column?

A novice question as I learn the Rcpp classes / data structures: Is there a member function to erase a row / column for an object of class Rcpp::NumericMatrix? (Or other types of type **Matrix -- I'm assuming it's a template…
alexwhitworth
  • 4,839
  • 5
  • 32
  • 59
10
votes
2 answers

How to change and set Rcpp compile arguments

I created a new Rcpp package (by using RStudio). This package contains a C++ function that is compiled by using the following compiler options: clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include…
Nick
  • 10,309
  • 21
  • 97
  • 201
10
votes
2 answers

Rcpp How to convert IntegerVector to NumericVector

I was wondering how to convert Rcpp IntegerVector to NumericVetortor to sample three times without replacement of the numbers 1 to 5. seq_len outputs an IntegerVector and sample sample only takes an NumericVector //…
Soren Havelund Welling
  • 1,823
  • 1
  • 16
  • 23
10
votes
8 answers

R CRAN, install library Rcpp fails after R3.2 upgrade

I upgraded from R-3.1 to R-3.2. OK ( Standard upgrade) But this upgrade seems to have lost all the installed packages ( ggplot2, quantmod, Rcpp among dozens and dozens of others). So installed many from the RStudio tools menu option. Most were…
Matt9
  • 101
  • 1
  • 1
  • 3