Questions tagged [rcpp]
Rcpp provides seamless integration of C++ code in R.
3,044
questions
0
votes
1
answer
32
views
How to configure R 4.3 to run on RHEL 8?
While trying to install the Rcpp package in R on our RHEL 8 server, I get this series of errors/warnings:
make: *** No rule to make target 'compilers'. Stop.
Warning in system(paste(MAKE, p1(paste(&...
1
vote
2
answers
64
views
Length of Rcpp::List differs between Windows and Mac
I am checking the length of an Rcpp::List object, and notice that I get different results on Windows than on Mac.
C++ code
Here is my C++ code, in the file "test.cpp". I have a Data class, ...
0
votes
1
answer
23
views
Rcpp Rf_warningcall compiler warnings
In the C++ code of the R/terra package I using the below to handle warnings:
template <typename... Args>
inline void warningNoCall(const char* fmt, Args&&... args ) {
Rf_warningcall(...
0
votes
1
answer
51
views
Rcpp warning: format string is not a string literal (potentially insecure)
Recently I have received the following error message on CRAN for some of my packages.
warning: format string is not a string literal (potentially insecure)
See for example the following link for the ...
0
votes
0
answers
47
views
How to access members of a List of DataFrames in Rcpp
I have an Rcpp function that includes a List of DataFrames as a parameter - let's call it "dflist." How would I access an element to read and/or assign to? And how would I return the ...
0
votes
0
answers
22
views
How to use libtorch from rcpp?
How call I use a libtorch from R, in armadillo and Arrayfire there are libraries like RcppArmadillo/RcppArrayFire. Is there something equivalent for libtorch or there is another way to use it?
0
votes
0
answers
42
views
Issues installing RcppArrayFire on Linux [duplicate]
I am trying to install the C++ library ArrayFire: https://arrayfire.com/
There is an R package for doing this: https://github.com/daqana/rcpparrayfire
However, I follow the instructions and install ...
1
vote
0
answers
31
views
Object type to use in RCPP for S7 object?
I'm writing a routine to close an SPI connection.
My Question: how do I declare an R7 (or S7) object for RCPP?
I've set this connection up as an R7 (S7) object. Here's the class definition
[r code]
...
3
votes
1
answer
76
views
How do I use Rcpp code in a stand-alone C++ program?
I am a Statistician who works a lot with scientists in other fields who are not using R but mostly C++. On occasion I would like to give them a C++ program they can run but that also uses R ...
0
votes
0
answers
33
views
Retrieve the content of multiples row and columns with Rcpp
i want to retrieve specified columns and rows from an NumericMAtrix.
dis is an NumericMatrix and i want to acces some columns and row based on sppInSample
This is my code snippet (this is not the ...
0
votes
0
answers
58
views
Compiling a library with Rcpp causing many 'unknown type'/'no member named' errors
I'm trying to compile a package that includes Rcpp functions and compilation is finding a ton of errors:
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source polowam
* installing to ...
3
votes
4
answers
134
views
Extract largest n values and their indices from a matrix
I have a matrix that is approximately 150'000 x 150'000 from which I need to extract the largest n values and their indices. n will also be large, somewhere between 10 million to 50 million.
I can't ...
1
vote
0
answers
40
views
R mclapply attempt in Rcpp
I would like someone who understands better than me to help me implement a mclapply with rcpp in a project I am working on. The fragment I want to transfer is this one, where data_by is a list of data....
0
votes
1
answer
107
views
R terra::aggregate "Not compatible with requested type" error when using custom function
I am attempting to aggregate a spatraster based on the most common value in each subset (i.e., modal), except if the value corresponding to water is the most common it must make-up more than 75% of ...
0
votes
1
answer
43
views
Why does this Rcpp code crash when using two push_back?
This is a simplified version of my code:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
List test_bug(int N) {
std::vector<int> inds;
std::vector<double> ...
1
vote
0
answers
170
views
Failed to install RcppArmadillo on Linux with OpenMP Error
I tried to install RcppArmadillo on a school Linux Hyper Cluster (which I do not have sudo access). I am installing via:
install.packages('RcppArmadillo')
in the R interface. The installation failed ...
1
vote
0
answers
36
views
Conflicting load by thread when running Rcpp with multithreads
I am trying to use c++ Pagmo library for parallelizing an optimization problem that takes too long to run serially. Some of the data used in the problem are R S4 class objects that are loaded from an ...
2
votes
1
answer
75
views
How to make a cpp (Rcpp) function that triggers "useful" error messages if the input types are wrong?
Consider this cpp function
// [[Rcpp::export]]
int timesTwo(int x) {
return x * 2;
}
If I input an object of wrong type in this function (e.g. "character"), apparently, it will not work ...
2
votes
1
answer
71
views
How to create large vectors with repeated elements fast?
There is a vector from which I want to make a new vector by taking its elements based on a sequence:
set.seed(0)
n <- 1000
ncval1 <- as.integer(n)
ncval2 <- ncval1:1L
ncval3 <- sequence(...
0
votes
0
answers
17
views
Subgraph count from a large graph (undirected) in a efficient way. How to increase performace of the R code? (Rcpp, doParallel)
I am working with a very large graph (The number of vertices in the graph is 1000+, which means I working with a (1000+ x 1000+) adjacency matrix). My laptop has an 8-core CPU and 8 gigs of RAM (...
0
votes
0
answers
57
views
Does Rcpp::stop() require an extra unprotect?
When terminating early with Rcpp::stop(), is it necessary to unprotect early in the below example?
I'm aware that I could have rewritten this using IntegerVector without the protect and unprotect ...
4
votes
3
answers
98
views
Erasing zeros from the vector element in Rcpp
I wrote the following code to erase zeros from the vector. I use the erase(i) function from the Rcpp library.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector erase_zero(...
0
votes
0
answers
35
views
L-BFGS converging with R optim, but not with RcppEnsmallen
I am using the below functions to call lbfgs using RcppEnsmallen to maximize a function defined by computeQval() :
double Qfunc::EvaluateWithGradient(const arma::mat& x, arma::mat& g)
{
// ...
4
votes
1
answer
45
views
Generating random matrix with a specific way (Rcpp)
I want to generate random matrix using Rcpp. In a following way;
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericMatrix testFunction1(IntegerVector idx, NumericMatrix x){
...
0
votes
0
answers
38
views
Rcpp long vector support
I was wondering if there is a way to make sure that my package which uses Rcpp can work with long vectors on machines that have long vector support and still work on machines that don't have long ...
0
votes
1
answer
112
views
Sum of matrix element in Rcpp
I am NewBie to Rcpp and R. I tried to compute the edge count or the wedge count from a adjacency matrix. For that I write the followin code in Rcpp.
#include <Rcpp.h>
using namespace Rcpp;
// [...
0
votes
1
answer
45
views
R CMD INSTALL on RcppArmadillo source package inhibits installing on other platforms
Running R CMD INSTALL on an RcppArmadillo source package skeleton (RcppArmadillo.package.skeleton()) on Ubuntu compiles the C++ files and supposedly does nothing else, as checked via Git diffing. ...
0
votes
1
answer
47
views
devtools::document() yields In loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called ‘Rcpp,’ [closed]
Dont know how to better phrase this.
Each time I source a Rcpp file or even compile the whole package I get the warning message:
Warning message:
In loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths(...
1
vote
2
answers
83
views
Rcpp error with linking external library?
I'm banging my head against the wall trying to get Rcpp to build a package for SPI on a Raspberry Pi.
My code/package is found at my GitHub: https://github.com/mnr/rpigpior/
When I run Rcpp::...
1
vote
0
answers
64
views
Rcpp minimum memory allocation
I noticed that calling Rcpp functions requires a minimum amount of allocation per call. Is this something that is unavoidable even with simple functions?
For example, calling a simple Rcpp function ...
0
votes
1
answer
31
views
undefined reference to `gsl_sf_lnfact' during install R package
guys, I am trying to install a R named MotifDiverge which depends on rphast, MotifDb, IRanges, Rcpp, RcppGSL, RcppArmadillo.I have installed all these dependecies. But somethings went wrong during the ...
1
vote
1
answer
35
views
What's the best practice setting a default value to a const reference DataFrame argument in Rcpp?
In a Rcpp function foo, the argument data may be a big dataframe so that I'd like use it as a const reference. Now I want to set the default value of it as an empty dataframe, so that users can simply ...
0
votes
0
answers
46
views
Failure to install R package RcppArmadillo on Arch
I am trying to install the R package RcppArmadillo on Arch. However, I run into issues during compilation:
* installing *source* package ‘RcppArmadillo’ ...
** package ‘RcppArmadillo’ successfully ...
3
votes
1
answer
75
views
Do I need to protect input SEXP?
In Rcpp, when running Rf_length on an input SEXP, do I need to further protect the input?
For example:
Would the below code be considered safe practice within Rcpp or is there a preferred method?
...
1
vote
0
answers
61
views
Calling R func from C++ without Rcpp::export
I've a C++ function that calls a user defined R function:
// [[Rcpp::export]]
void listener(ClientCacheEntryCreatedEvent<int> e) {
int key = e.getKey();
Rcpp::Function f("addElement&...
0
votes
0
answers
45
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
103
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::...
1
vote
1
answer
93
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
67
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
74
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
42
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
47
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
24
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
52
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
51
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
108
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
35
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
162
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
66
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
96
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:...