Questions tagged [rcpp]
Rcpp provides seamless integration of C++ code in R.
3,014
questions
-2
votes
0
answers
52
views
R package build error: clang: error: linker command failed with exit code 1 (use -v to see invocation) [closed]
I am building a R package to do some matrix calculation including three rcpp files and one .h file.
The .h file is:
#ifndef HDTS_H
#define HDTS_H
#include <RcppArmadillo.h>
#include <...
0
votes
0
answers
38
views
Rcpp, Iterate DataFrame
I'm trying to realize a simple interop "R+Rcpp" and have strange problem with DataFrame::iterator and std::algorithm methods.
I have this code written on Rcpp.
struct TradeIndex
{
Date ...
1
vote
0
answers
88
views
Extent of Thread Safety in R/ Rcpp
I know that R, and by extension Rcpp, are generally not thread-safe. This script e.g. crashes R:
// [[Rcpp::plugins(openmp)]]
#include <Rcpp.h>
#include <omp.h>
// [[Rcpp::export]]
Rcpp::...
0
votes
1
answer
57
views
Fast way to permute rows of matrices in Rcpp or RcppArmadillo?
I'm running a stationary bootstrap algorithm on an N x M matrix, X, where both N and M are on the order of 1500 to 3000.
The bootstrap matrix of index permutations, Y, is N x B, where B is, say, 10,...
0
votes
0
answers
62
views
Is it safe to access (read-only) R matrices within a Rcpp::List from an openMP parallelized loop using a std::vector<double*>?
I wrote a piece of Rcpp code to speed up some treatment involving a R list of numeric matrices.
As the number of matrix within the R list may reach hundreds of thousands, I started parallelizing this ...
2
votes
1
answer
59
views
Rcpp Compile Attributes creates void argument
In developing the R package BayesMallows which uses Rcpp as well as unit testing with Catch via the testthat package. Recently we have noticed an issue which creates an LTO issue on CRAN. Here is a ...
0
votes
0
answers
36
views
Armadillo C++: most efficient way to calculate using submatrix
Suppose I have two armadillo matrices A and B, and I want to calculate matrix product of two submatrices from both. I wonder what is the most efficient way to achieve it? Thanks
arma::mat A;
arma::mat ...
0
votes
0
answers
41
views
How to pass an array variable from R to C++ in a parallel Rcpp code in a thread safe way?
I would like to pass an array in a parallel code with RcppParallel.
First, I can pass an array with arma::cube. Is an arma::cube variable thread safe in a parallel code?
Second, to make a ...
0
votes
0
answers
19
views
How to convert a NumericVector to RcppParallel::RVector<float> or a NumericMatrix to RcppParallel::RMatrix<float>?
In a parallel code with Rcpp, I convert a NumericVector variable to RcppParallel::RVector<double>. I also convert a NumericMatrix variable to RcppParallel::RMatrix<double>.
To speed up the ...
0
votes
0
answers
49
views
Coordinates from Cell Number
I need to obtain the coordinates from a terra SpatRaster cell number in C++. I am aware of terra::xyFromCell. However, I need to keep this function in C++.
Consider the following simplified example:
#...
1
vote
1
answer
40
views
Exporting RcppParallel::RVector vs std::vector
Consider the following serial example function:
// [[Rcpp::plugins(cpp20)]]
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::NumericVector example_fun(int n) {
Rcpp::NumericVector result (n);
...
1
vote
1
answer
98
views
Develop a custom Rcpp function to be used with terra::focalCpp to calculate the median of values within a moving window
I'm trying to replicate the use of median within R that includes na.rm=TRUE as Rcpp code. I found this really useful link that includes the exact code I need for implementing Rccp median with na.rm=...
0
votes
0
answers
29
views
Testing package with C++ function in GitHub Actions throws error: R is already initialized
When I R CMD check my package on GitHub Actions, I am getting the error "R is already initialized", during the tests, and only on Ubuntu. Tests run ok in MacOs and Windows.
test_that("...
0
votes
0
answers
58
views
Impossible to install RcppParallel package
To install the package rstan in R, the package RcppParallel is required, but I'm not able to install it in R/4.3 on a Linux machine (cluster). I tried different solutions proposed (e.g., install from ...
2
votes
1
answer
63
views
Repeated Rcpp NumericVector
I have a vector x from which I want to create a vector y consisting of multiple copies of x. So, if x is {1, 2, 3} and the number of repetitions n is 3, y would be {1, 2, 3, 1, 2, 3, 1, 2, 3}. x must ...
2
votes
1
answer
87
views
How to replace exit() from a C++ library to Rcpp?
In the C++ library CGAL there are these lines:
void exit( Locate_type& lt, int& li, int& lj ) const
{
lt = prev_lt(); li = prev_li(); lj = prev_lj();
}
std:...
0
votes
1
answer
152
views
Develop a custom Rcpp function to be used with terra::focalCpp to calculate the percent of a specific value within a moving window
I'm trying to speed up some raster processing I'm doing using terra::focal by using focalCpp.
Here is some example data with 1s and NAs included to replicate an actual dataset
nr <- nc <- 50
r &...
2
votes
0
answers
59
views
Use R connection object from Rcpp
I am writing some C++ functions for fast reading of binary files. Ideally I would have something like this:
con <- file("path/to/your/file.bin", "rb")
extract1 <- ...
0
votes
0
answers
38
views
DataFrame Manipulations using RCPP
I am trying to manipulate Big Data Frame (Almost in GB's). I have tried all possible solutions in R.
As We all know RCPP known for it's speed & efficiency.
I come across DataFrame::create() ...
1
vote
1
answer
27
views
Mapping Rcpp NumericVector to *static* or *fixed-size* Eigen Vectors?
This thread provides an example of converting an Rcpp::NumericVector to an Eigen::VectorXd:
Rcpp::cppFunction("bool conv(NumericVector X) { \
Eigen::Map<Eigen::VectorXd> \
XS(...
0
votes
0
answers
60
views
what's wrong with my plugin for inline::cxxfunction()?
I can run some example code from inline::cxxfunction()'s documentation:
inline::cxxfunction(signature(x = "integer", y = "numeric"),
"return wrap( as<int>(x)...
0
votes
1
answer
55
views
rcpp package compilation process map to cxxfunction compilation
I wrote an R package that compiles user-written c++ code with the help of Rcpp and RcppEigen. Every time the user wants to create a new model, he/she must write three files:
one header file for the ...
1
vote
0
answers
46
views
Using the precompiled static library instead of compiling the 3rd party library during Rcpp package installation
I am trying to create an R package that has some functions in main.cpp which is dependent on an external Cpp library, libDAI. Let's say DAI1.cpp, DAI1.h, DAI2.cpp, DAI2.h and main.cpp are in the /src. ...
0
votes
1
answer
36
views
Rcpp Eigen inplace matrix multiplication error
I'm new to Rcpp and Eigen and I'm trying to run a inplace matrix multiplication while I run into this error. R didn't tell me what the error is about.
SEXP cpp_hom_crit(
const Eigen::Map<Eigen::...
1
vote
2
answers
69
views
Building custom R package leads to undefined symbol
I'm currently working on a R package that depends on Eigen, EigenRand, and GSL. I was able to successfully build the package when it just depended on Eigen and GSL. Now, when I build, the compile is ...
0
votes
1
answer
59
views
LBFGS wrapper in RcppNumerical
I wrote a function to numerically find the quantiles of the following finite mixture of normals
In order to do that I am minimizing . I am using the wrapper of LBFGS from RcppNumerical for the ...
0
votes
1
answer
114
views
How do I connect to a redis database using password and ssl?
I'm trying to use R and RcppRedis to connect to a redis database that requires SSL and a password. I'm building the R env inside a docker container in which I compile hiredis with SSL enabled, but ...
2
votes
1
answer
69
views
Stark Rcpp performance difference within precompiled R package and sourced locally with cppFunction()
I'm noticing a huge difference between Rcpp's performance within a precompiled R package and when sourced locally using an on-the-fly cppFunction(<source code>).
Here is a minimal reproducible ...
0
votes
1
answer
229
views
Rcpp & main/optim.c - How to translate `void *ex` after passing the variable through `nmmin()`?
Main question: How to format a complex struct in Rcpp that will be accepted by optim.c? and how will this struct be modified when returned to the defined optimfn function?
Background: I'm writing an ...
4
votes
2
answers
105
views
Extracting a submatrix with Rcpp
In a package of mine, I extract a submatrix B from a matrix A as follows:
NumericMatrix extractColumns(NumericMatrix A, IntegerVector indices) {
int n = indices.size();
int m = A.nrow();
...
0
votes
0
answers
51
views
boost_program_options_FOUND issue in RBuildTools when compiling in windows
I'm trying to compile C++ code for an R package and during the 'Rcmd.exe INSTALL' call this error about boost_program_options_FOUND happens. I've put 'set(Boost_USE_STATIC_LIBS ON)' in my CMakeLists....
4
votes
1
answer
73
views
Using R's integrate() with functions from R and Rcpp
Function dt in R can sometimes throw warning messages depending on the values used in the computation.
For example, dt(1.424781, 1486, -5) shows
Warning messages:
1: In dt(1.424781, 1486, -5) :
...
0
votes
0
answers
25
views
Package development: R CMD Check cannot find R package (no namespace error) used in Rcpp function
I have an R package where I have written some functions in Rcpp. In a new function, I am using the fastglm package in Rcpp using this code:
double estAUC(NumericMatrix dmatrix, NumericVector y) {
.
...
2
votes
2
answers
85
views
R Package using Rcpp and C++20
I made a simple R Package using Rcpp but when I set
SystemRequirements: C++20
on DESCRIPTION I have the following error on build.
clang++ -arch x86_64 -std=gnu++20 -I"/Library/Frameworks/R....
1
vote
2
answers
119
views
Efficiently find duplicated vectors in C++
I'm working on a R package dealing with 3D meshes. I have a function which constructs a parametric mesh but for certain parameterizations it can generate duplicated vertices (numeric vectors of length ...
3
votes
1
answer
142
views
Why is Boost implementation 5-10x slower than R's
I am building an app that frequently computes the regularized incomplete beta function. The app is written in C++ and calls R::pbeta(). When I tried to multithread the app, some warning messages from ...
1
vote
1
answer
87
views
Problem in modifying shared armadillo matrix with OpenMP
I tried using omp in RcppArmadillo in the following toy example
#include <RcppArmadillo.h>
#include<omp.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::...
1
vote
1
answer
86
views
How to use mlpack in my Rcpp code in macOS
I am trying to build an R package using mlpack. As suggested in this link I am using the following cpp function
#include <Rcpp/Rcpp>
#include <mlpack.h>
// Two include directories ...
0
votes
1
answer
105
views
Problem with Using RcppMLPACK in My Own R Package
I am trying to develop an R package using the kmeans functionality from RcppMLPACK.
I in including the header part below:
#include <RcppArmadillo.h>
#include <RcppMLPACK.h>
#include <...
2
votes
1
answer
60
views
Catching LAPACK errors in Armadillo
I'm attempting to calculate the SVD of a matrix using RcppArmadillo.svd() is supposed to return 0 if the SVD failed. However, I have encountered a matrix for which I get the error code BLAS/LAPACK ...
2
votes
0
answers
48
views
Ideas for fast rank-two update of symmetric positive definite matrix
I have the following task: Let Sigma be a dxd covariance matrix, let B be a dx2 matrix of arbitrary columns of Sigma and let H be a symmetric 2x2 matrix.
I need to make the following update of Sigma
...
2
votes
1
answer
155
views
Implement custom Cpp function for use in terra::focalcpp in R
I want to use a custom function over a moving window on a matrix. I have been using terra::focal. This works well but R-based custom functions are quite slow and this represents a real bottleneck in ...
2
votes
1
answer
73
views
Rcpp "no such symbol" in shared library, but symbol certainly exists
I am building a complex R package using Rcpp that integrates C++ with a large external library (I'll call it my_lib), which itself is dependent on several C++ libraries. I've built all of the external ...
1
vote
2
answers
76
views
How to input both character and numeric input vectors in an rcpp fuction?
I'm fiddling around with the below Rcpp code which works like R's expand.grid(). The goal is to take an unknown quantity of input vectors of any data class and output all combination across the inputs....
0
votes
0
answers
50
views
Parallel processing with Rcpp function - would I get less overhead using foreach or using RcppParallel?
I have an Rcpp function which I am calling from R. I have made this parallel by using the 'foreach' package.
However, based on some brief experiments, the parallel computation is only worth it when ...
0
votes
0
answers
22
views
Running RInside example produces Fatal error: unable to initialize the JIT. Why?
After installing the RInside package from within R I tried to compile and run the examples provided. Changing directory to $R_HOME/library\RInside\examples\standard the command
make -f Makefile.win ...
1
vote
1
answer
46
views
I have a strange problem when calling runif in an Rcpp routine
I have a routine called test written in Rcpp which has a single argument, a function called g. In the routine I call another Rcpp routine called ru that returns a uniform [0,1]. (The same issue ...
0
votes
0
answers
31
views
Rcpp error: no matching function for call to 'distance(Rcpp::Vector<14, Rcpp::PreserveStorage&, Rcpp::Vector<14,Rcpp::PreserveStorage>&)'
I am new to Rcpp. I am trying to write Rcpp code and I have this error when compile the code enter image description here
And here is the code I write , I think the other code is find just this part ...
0
votes
0
answers
30
views
Rcpp function within R loop crashes, whereas outside of the loop it doesn't
I wrote the following code in Rcpp
#include <RcppArmadilloExtensions/sample.h>
#include <random>
#include <iostream>
#include <cmath>
#include <vector>
#...
1
vote
1
answer
84
views
Can't solve Valgrind memory issues in Rcpp code
I have posted my package on CRAN and recived Valgrind's check results revealing some memory leaks (link). Unfortunately, I can't reproduce these errors. Therefore, I have some hypothesis why these ...