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
210
votes
10 answers

Speed up the loop operation in R

I have a big performance problem in R. I wrote a function that iterates over a data.frame object. It simply adds a new column to a data.frame and accumulates something. (simple operation). The data.frame has roughly 850K rows. My PC is still working…
Kay
  • 2,109
  • 3
  • 13
  • 3
119
votes
4 answers

Where can I learn how to write C code to speed up slow R functions?

What's the best resource for learning how to write C code for use with R? I know about the system and foreign language interfaces section of R extensions, but I find it pretty hard going. What are good resources (both online and offline) for…
hadley
  • 102,019
  • 32
  • 183
  • 245
103
votes
5 answers

R install.packages returns "failed to create lock directory"

I get this error when downloading the Rcpp package: > install.packages("Rcpp", dependencies=TRUE) Installing package(s) into ‘/home/me/src/Rlibs’ (as ‘lib’ is unspecified) trying URL…
tflutre
  • 3,354
  • 9
  • 39
  • 53
83
votes
1 answer

Understanding the contents of the Makevars file in R (macros, variables, ~/.R/Makevars and pkg/src/Makevars)

I am trying to understand the role and relationship of the macros/variables set in ~/.R/Makevars and package_directory/src/Makevars when installing/building own R packages. Suppose these files look like ~/.R/Makevars CXX = g++ CXXSTD =…
NoBackingDown
  • 2,144
  • 1
  • 19
  • 25
70
votes
2 answers

Rcpp package doesn't include Rcpp_precious_remove

I have been trying to create a database and installed the "DBI" package, but I am still facing this error. I reinstalled DBI and RSQLite package, but they don’t seem to work. library("DBI") con <- dbConnect (RSQLite::SQLite(), dbname =…
Laxmi Agarwal
  • 702
  • 1
  • 4
  • 8
61
votes
5 answers

Practical limits of R data frame

I have been reading about how read.table is not efficient for large data files. Also how R is not suited for large data sets. So I was wondering where I can find what the practical limits are and any performance charts for (1) Reading in data of…
Egon
  • 3,718
  • 3
  • 34
  • 48
55
votes
7 answers

ld: warning: text-based stub file are out of sync. Falling back to library file for linking

When I am trying to sourceCpp, it gives a warning: ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file …
MOOn
  • 651
  • 1
  • 5
  • 4
44
votes
7 answers

Using 3rd party header files with Rcpp

I have a header file called coolStuff.h that contains a function awesomeSauce(arg1) that I would like to use in my cpp source file. Directory Structure: RworkingDirectory sourceCpp theCppFile.cpp cppHeaders coolStuff.h The Code: #include…
politicalEconomist
  • 1,041
  • 1
  • 14
  • 19
40
votes
1 answer

RcppArmadillo pass user-defined function

Consider the following R code, ## ----------- R version ----------- caller <- function(x=1:3, fun = "identity", ...){ ## do some other stuff ## ... ## then call the function eval(call(fun, x)) } fun1 <- function(x, ...){ x + x } fun2…
baptiste
  • 75,767
  • 19
  • 198
  • 294
35
votes
2 answers

How do I create a list of vectors in Rcpp?

I'm writing an Rcpp module an would like to return as one element of the RcppResultSet list a list whose elements are vectors. E.g., .Call("myfunc")$foo should be something like: [[1]] [1] 1 [[2]] [1] 1 1 [[3]] [1] 1 1 1 (the exact numbers are…
Jonathan Chang
  • 24,567
  • 5
  • 34
  • 33
35
votes
2 answers

What are productive ways to debug Rcpp compiled code loaded in R (on OS X Mavericks)?

What is the most productive and quickest way to debug shared objects that are loaded into R, in particular on OS X Mavericks? I'm primarily interested in debugging compiled Rcpp code. I have read the R externals on debugging compiled code…
FXQuantTrader
  • 6,821
  • 3
  • 36
  • 67
33
votes
3 answers

Why is this naive matrix multiplication faster than base R's?

In R, matrix multiplication is very optimized, i.e. is really just a call to BLAS/LAPACK. However, I'm surprised this very naive C++ code for matrix-vector multiplication seems reliably 30% faster. library(Rcpp) # Simple C++ code for matrix…
Cliff AB
  • 1,160
  • 8
  • 15
31
votes
5 answers

Replace negative values by zero

We want to set all values in an array zero that are negative. I tried out a a lot of stuff but did not yet achieve a working solution. I thought about a for loop with condition, however this seems not to work. #pred_precipitation is our…
Fabian Stolz
  • 1,935
  • 7
  • 27
  • 30
29
votes
1 answer

Basic documentation for Rcpp

I want to look into rcpp to improve the speed of some of my R code without having to resort to messy C++ code (I've had some success with that, but it looks like code from hell). So, I checked the documentation provided with Rcpp, and also the…
Nick Sabbe
  • 11,684
  • 1
  • 43
  • 57
29
votes
4 answers

Can't run Rcpp function in foreach - "NULL value passed as symbol address"

Let me say first that I've read Writing R Extensions, the Rcpp package vignette, and that I've built a package from Rcpp.package.skeleton(). Since building my package, I added a function, multiGenerateCSVrow(), and then ran compileAttributes() on…
Patrick McCarthy
  • 2,478
  • 2
  • 24
  • 40
1
2 3
99 100