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
0 answers

How to pass a file stream as an argument to a Rcpp-function?

I am new to Rcpp. My problem: I want to have a function (writeToFile) that writes to a file on my hard drive. This function shall be called several times within a second function (foo). Thus I want to open the stream only once, write to the file…
SimonS
  • 43
  • 4
1
vote
0 answers

Calling a C function from a R package with a C++ function of another

Hello I have developed a package using Rcpp and I would like to use within this package some C code from another package (for reference the package in question is rkdb and the function is from_any_k_object) I would like to know if this is possible…
statquant
  • 13,672
  • 21
  • 91
  • 162
1
vote
1 answer

RInside: parseEvalQ 'Parse Error' causes each subsequent call to parseEvalQ to give a 'Parse Error' even if exception handled

My code, which tries to emulate an R shell via C++, allows a user to send R commands over a tcp connection which are then passed to the R instance through the RInside::parseEvalQ function, during runtime. I have to be able to handle badly formatted…
C Noble
  • 11
  • 2
1
vote
0 answers

Error while Checking custom package " Error in library("PHit") : there is no package called 'PHit' "

I'm using Rcpp to convert a bunch of functions written in C++ into a R package and I've managed to get past all the bugs in the code, but when I run the check, all the code checks out, but when it loads my package "PHit" it gives me that error and…
kyle j
  • 11
  • 3
1
vote
1 answer

Using R's "which" function in Rcpp, not returning values

I've written an Rcpp function to call R's which function to check for equality. It compiles fine but it appears that it is only returning values for the first item in a vector: mywhich(samplevector, samplevector[1]) returns a value,…
ConorM
  • 33
  • 1
  • 5
1
vote
1 answer

Converting a for loop with t(apply()) from R into C++ for use with Rcpp

I'm trying to convert a for loop written in R into C++ for use with Rcpp; specifically an 'apply'-type function with transpose. The function takes a .gen file and converts it to alleles: I've read through Nick Ulle's Getting started with Rcpp and a…
1
vote
2 answers

Rcpp::stop() crashes R under g++

Here's a simple test function that calls Rcpp::stop() #include NumericVector dostop() { Rcpp::stop("foo"); NumericVector x(1); return x; } With clang on OS X, this performs as expected: > library(Rcpp) > sourceCpp('stop.cpp') >…
Nobody
  • 153
  • 7
1
vote
0 answers

Evaluation R code in parallel using OMP and Rcpp

I have this code //[[Rcpp::export]] SEXP Eval(string expr,Environment env){ SEXP s = R_ParseEvalString(expr.c_str(),env); return s; } void ForEval(SEXP env){ string code = "rnorm(10)"; for(int i=0;i<10;++i){ SEXP res =…
Manos Papadakis
  • 564
  • 5
  • 17
1
vote
1 answer

Rcpp share same roxygen between two functions

Consider the following functions: //' Provides some stuff AB //' @param a integer that responsible for stuff A //' @param b integer that responsible for stuff B //' @export // [[Rcpp::export]] NumericVector foo1(int a, int b) { //some code } //'…
Bogdan
  • 864
  • 10
  • 18
1
vote
1 answer

Improve performance of the R program using Rcpp

I'm trying to speed up my R code - I'm wondering if this is something that can be done in Rcpp. This is my code that I started to write. library(Rcpp) cppFunction('int cont.run_C(int reps=10000,int n=10000,int d=0.005,int l=10 ,int s=0.1) { r =…
DDuri
  • 13
  • 3
1
vote
1 answer

Is there any way to make Rcpp stop defining NDEBUG?

Why does assert not work here? ^ Apparently, Rcpp has a habit of defining NDEBUG on its own, even if not defined by myself. m@m-X555LJ:~/wtfdir$ cat WTF.r #!/usr/bin/Rscript library(Rcpp) sourceCpp("WTF.cpp") m@m-X555LJ:~/wtfdir$ cat…
user4385532
1
vote
2 answers

How to conditionally summarize on other entries in the group - R

In my dataset I have Cartesian coordinates of different items overtime identified by an EventID, event_type, ID number, x position, y position, identity type, broad category, and frame id number. What I need to do is go for each EventID, event_type…
1
vote
0 answers

rhub compilation warning on Ubuntu 16.04

We are developing an R package that contains compiled code (using Rcpp). We check the package builds on rhub (to test builds on multiple platforms) with check_for_cran() function. For Ubuntu 16.04, we get the following warning * checking…
akashrajkn
  • 2,295
  • 2
  • 21
  • 47
1
vote
2 answers

Use a C++ function as an argument for another C++ function called by an exported Rcpp function

I saw that it is possible to pass an R function as argument into C++ using Rcpp. For example, you can do: // [[Rcpp::export]] arma::mat example_cpp_func(Rcpp::Function my_r_func, arma::mat a){ return Rcpp::as(my_r_func(a)); } That is…
Ari.stat
  • 463
  • 4
  • 13
1
vote
2 answers

How to get column names even if it is NULL in Rcpp?

I want to get column names of a matrix to set another one, but if matrix does not have column names (or is set to NULL), the following code crashes my R session. CharacterVector cn = colnames(x); The following code is the way how I get column names…
Sezen
  • 447
  • 1
  • 5
  • 17