3,102 questions
-1
votes
0
answers
48
views
OpenMP schedule(dynamic) fails in RcppEigen on macOS Sequoia 15.6.1 (symbol not found in flat namespace)
I am running a straightforward parallelized computation using RcppEigen and OpenMP.
Here is a minimal reproducible example of the code:
// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::plugins(openmp)]]
#...
Best practices
0
votes
1
replies
27
views
Using stats link functions in Rcpp
How can I use C functions from the stats package in C++ code written with Rcpp?
I'd like to use the logit link-function and link-inverse from the stats package. Since it's just two simple functions, I ...
2
votes
1
answer
139
views
How to get a length one sub-vector of a NumericVector in Rcpp
How can I get a length one sub-vector of a NumericVector in Rcpp. Similar to the drop=FALSE argument in [ in R. The only solution I found so far is to use a length 1 NumericVector as an auxillary ...
4
votes
2
answers
214
views
Sum the vectors stored in the list using Rcpp
Suppose I have the following list of vector
List <- list(c(1:3), c(4:6), c(7:9))
To get the required result I have the following code in Rcpp
totalCpp <- {"#include <Rcpp.h>
using ...
0
votes
1
answer
107
views
How to resolve the error: Error: package or namespace load failed for 'my_package' etc
R package using RcppParallel builds but fails to install due to undefined TBB symbols
Body:
I'm developing an R package using RcppParallel to compute distance matrix. The package builds successfully, ...
3
votes
1
answer
84
views
Configure script does not generate makefile properly for 3rd party library used in R package with RCPP (rtools44)
We are currently working on a package utilizing the constraint programming solver Gecode (6.2). For the sake of usability we would like to include the Gecode source files with the package, so users do ...
1
vote
1
answer
104
views
OpenMP thread affinity not working in Rcpp package: "Affinity not supported on this configuration"
I'm developing an R package using Rcpp with OpenMP for parallelization. I'm facing an issue where threads are randomly spread across CPU cores, leading often to threads beeing scheduled primarily on ...
0
votes
2
answers
74
views
Strange behaviour of Rcpp when generating random numbers
I have a routine written in Rcpp that is supposed to generate random numbers. Strangely enough, if I also call a completely unrelated routine, it always returns the same number. Here is a toy example:
...
0
votes
0
answers
169
views
loading the terra package makes R crash
Using R 4.5.0 on a Windows 11 computer, loading the terra package with library(terra) in a clean R session makes R crash. The crash occurs half the time only; half the time it is successful. I noticed ...
1
vote
1
answer
138
views
RcppArmadillo : 'gfortran' not found , MAC M3, Sonoma 14.5
I was trying to brush up my RCpp skills and attempted to use sourceCpp() to use a simple hello_world.cpp program.
However, I encounter
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-...
0
votes
1
answer
112
views
How to unit test Rcpp function with R code and testthat within a package
Suppose I want to unit test a small Rcpp function I wrote by feeding it and the reference implementation of the function in R the same input and comparing the output.
Below is a very simple example (...
2
votes
0
answers
126
views
Error on Macbook Air M1 (2020) C++ compiler when using Rcpp and NIMBLE?
I am working on a problem involving NIMBLE in R and I am getting the following error on compilation:
> Cmodel <- compileNimble(Rmodel)
Compiling
[Note] This may take a minute.
[Note] Use '...
3
votes
0
answers
108
views
How to add a Fortran routine to an R package with Rcpp
I want to add a Fortran routine (from a package that I found on the internet) to my own R package. My R package compiles just fine, and so does the package with the Fortran code, but when I add that ...
4
votes
1
answer
171
views
Rcpp package error for RShiny app republication
I'm having issues re-publishing an RShiny app I have published (and re-published) previously.
The app runs fine locally (in the RStudio preview and if I run it in my browser), but when I try to re-...
0
votes
1
answer
81
views
Can you run C code in R in Windows without losing compatibility?
I'm building a R package from an existing C library using RStudio. I was testing the library in Windows using an Ubuntu terminal with WSL. It mainly uses these two commands:
gcc -x c -o pvalues.so src/...
1
vote
0
answers
80
views
RcppParellel and RcppArmadillo seeds problems
I have an RcppArmadillo code that runs sequentially and I am trying to adapt it for parallel compilation with RcppParellel.
The code is a copy paste of sequential code and actually runs faster. Yet ...
0
votes
1
answer
68
views
Why does Rcpp + RcppParallel with Rcpp::List throw me a fatal error?
I run R + Rcpp + RcppParallel from RStudio.
I run a parallel loop that works if I do not use a Rcpp::List in the worker, but throws an abort if I use the Rcpp::List in the worker (even in a trivial ...
0
votes
0
answers
109
views
Running a Rcpp function in parallel is slower than running it in serial
I am developping a R function than used a function code in Rcpp (i am already new to this).
I wanted to make simulations and run the same r functions in a cluster of x cores. Unfortunately when I do ...
0
votes
0
answers
131
views
C++ AVX2 custom functions (e.g., "exp") not working on Windows (but work on Linux)
this post is somewhat related to this post I did a couple of days ago:
C++ AVX2 Function Pointers/std::function not working on Windows (but work on Linux)
Now, since then, thanks to the useful ...
1
vote
0
answers
136
views
C++ AVX2 Function Pointers/std::function not working on Windows (but work on Linux)
I'm experiencing an issue where passing AVX2 functions through function pointers or std::function works fine on Linux, but crashes on Windows. Direct AVX2 operations work fine on both platforms.
...
1
vote
1
answer
60
views
superlu causing problems with mlpack in Rcpp
I have the following Rcpp code
#include <RcppArmadillo.h>
#define _USE_MATH_DEFINES
#include<cmath>
#include <boost/math/special_functions/bessel.hpp>
#include <mlpack.h>
#...
0
votes
0
answers
22
views
R parallel loop foreach never ends in Linux Fedora 39
The code bellow executes in parallel the function "mhrcmx_dep_rep_int" (written in c++) of my R package "mhrcmxIntDepL":
### paths
path = paste0(fs::path_home(),'/rcpedroso/CAI/'); ...
1
vote
1
answer
329
views
How can I extract data from a GeoTIFF at specific x, y co-ordinates in C++
I am an R user but a novice in C++. I need a C++ workflow that returns the value of a GeoTiff at a specific (x, y) coordinate. The GeoTiff contains 1 layer. The layer is a 2-dimensional array. Each ...
-1
votes
1
answer
92
views
Automatically adapting to arma::mat or arma::sp_mat in an Rcpp::List?
I would like to store and operate an array of matrices (or pointers to them), which could be either arma::mat or arma::sp_mat of varying dimensions (passed from R via Rcpp). What would be the easiest ...
0
votes
0
answers
104
views
How to maintain data consistency between R and Rcpp?
I'm doing matrix calculations, and in order to improve performance, I'm programming this process using Rcpp. However, I found that the results of the two calculations could not be consistent because ...
1
vote
1
answer
91
views
Tbb based row sum of an armadillo matrix
Following the tbb example for parallel_reduce here with a basic datatypes, I wanted to try and implement a tbb version of a row sum of an Armadillo matrix. (I realize the use of arma::sum for this ...
2
votes
1
answer
136
views
How to use `Rcpp` to implement a similar function for regression analysis of `lm` functions in R?
In order to speed up the calculation for very large matrices, I use Rcpp to perform the calculation, which involves regression analysis. I noticed in r's documentation that lm uses the qr ...
1
vote
1
answer
58
views
Understanding error messages in Rcpp code with structures and functions
I'm getting a couple of error messages when I run the following code that I do not understand -
expected initializer before 'add_f'
no matching function for call to 'try_grid::try_grid(Rcpp::...
0
votes
0
answers
73
views
Error in running cpp files through Rcpp through the compilation of gfortran in Mac OS 15.1
I was trying to download MetaboAnalystR in my Mac mini M4. It's required to install gfortran to compile the cpp. I went through the process in this page.
However when I ran the test cpp file, it ...
2
votes
1
answer
104
views
Rcpp incorrect subscript out of bounds warning
I get a subscript out of bounds warning, but the function seems to work fine and I don't see why the warning occurs. Here is a minimal example:
NumericVector foo(double seed, int steps) {
...
2
votes
1
answer
102
views
Matrix operations in Rcpp
I'm very new to Rcpp and I would like to manipulate a matrix in Rcpp. I have a 3D matrix in R and I would like to transfer it to a function in Rcpp. I can't seem to do so!
include <Rcpp.h>
...
2
votes
1
answer
69
views
Package with Rcpp ignores #include <stack>
I want to use a std::stack in a C++ function inside an R package. Consider the following example C++ file:
// [[Rcpp::plugins(cpp20)]]
#include <Rcpp.h>
#include <stack>
// [[Rcpp::export]...
1
vote
0
answers
84
views
How to I use an Rcpp function within an R function when building an R package?
I am trying to build an R library with an R function that call an Rcpp function. I used to call this Rcpp function through sourceCpp and it worked well.
When trying to make the R library using roxygen ...
0
votes
0
answers
217
views
Compilation failed when installing Rcpp on RHEL8
When I try to install R Package Rcpp I got following ERROR Message.
> install.packages("Rcpp")
Installing package into ‘/<SOMEDIR>/r/lib_user’
(as ‘lib’ is unspecified)
trying URL '...
1
vote
1
answer
59
views
Why does rcpp::warning() not work within openmp loop
Consider the following reprex:
//test.cpp
#include <Rcpp.h>
// [[Rcpp::plugins(openmp)]]
using namespace Rcpp;
#ifdef _OPENMP
#include <omp.h>
#endif
//[[Rcpp::export]]
void ...
2
votes
1
answer
85
views
R's NA_REAL conversion to integer in C++ now gives 0 on Mac (instead of NA_INTEGER)
Reprex:
// [[Rcpp::export]]
int dbl2int(double x) { return x; }
/*** R
dbl2int(NA_real_)
*/
Rcpp::sourceCpp("test-dbl2int.cpp")
On Mac, it outputs 0, while it outputs NA_INTEGER on Windows ...
1
vote
1
answer
84
views
Rcpp C++ binary object not found when adding a new function to an old R package
I am running the latest R and Rcpp under MacOS Sonoma. I am attempting to add a new function call C++ code to a very old package (Hmisc), setting things up using Rcpp::compileAttributes(). The new R ...
0
votes
0
answers
62
views
List to Vector in Rcpp
Is there an elementary function in Rcpp to transform a Rcpp::list object within Rcpp to a Rcpp::NumericVector? One way would be to import the unlist function of R, but thats not very elegant.
0
votes
0
answers
93
views
Debugging RCPP with VS Code
I am trying to reproduce the example here to debug RCPP code with VS Code on Windows.
Here is my launch.json config:
{
"version": "0.2.0",
"configurations": [
{
...
2
votes
1
answer
69
views
How to call the dnorm C code from Fortran or C code that I call from R?
I have an R program, that calls two R functions, f1 and f2.
f1 calls stats::dnorm (which is an R wrapper for some C code, called C_dnorm).
f2 calls extraDistr::dgev (which is an R wrapper for some CPP ...
2
votes
1
answer
161
views
Error when trying to compile an R package with CUDA and Rcpp
I'm building a small R package using CUDA and Rcpp as a learning exercise (using Building a tiny R package with CUDA and Rcpp as inspiration). It includes a single function that takes a device ID and ...
0
votes
1
answer
2k
views
error sourcing c++ with Rcpp in Mac OS Sonoma 14.5: fatal error 'cmath' file not found
I have recently moved to Mac OS Sonoma 14.5 and I am now trying to use my previous R script based on Rcpp (sourcing C++ in R).
I have been having serious difficulties understanding how to link the ...
1
vote
1
answer
189
views
Failing to compile package from Mac [duplicate]
I'm trying to install a package in R, and I get the following error:
clang: error: unsupported option '-fopenmp'
This, is after I got an error:
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-...
0
votes
1
answer
100
views
Cannot compile with RcppParallel on Windows
I have installed Rcpp, RcppParallel and I was testing simple function, written in .cpp file.
#include <RcppParallel.h>
#include <Rcpp.h>
#include <vector>
using namespace ...
0
votes
0
answers
79
views
sourceCpp error: G__~1.EXE: error: unrecognized command line option '-std=gnu++17'
I switched from R-3.6.3 to R-4.3.1 and R-4.4.1.
I tried to sourceCpp() some *.cpp which worked fine for R-3.6.3, but not for R-4.3.1 and R-4.4.1. The error is copied below.
Rcpp::evalCpp("2 + 2&...
1
vote
0
answers
39
views
How to move all individuals from one class to another at specific time step Boost ODE C++
I am trying to write a system of differential equations that can account for fecundity and maturation occurring at specific time steps throughout the years. Currently, this is the code that I have set ...
1
vote
1
answer
105
views
Docker image build not working for glmnet and Amazon Linux
I am creating a Dockerfile to run R workloads in Lambda based on a template from the lambdr package, which relies on an Amazon Linux base image and yum package manager. I need glmnet for one of the ...
1
vote
1
answer
208
views
How can I re-install a R package which uses Rcpp?
In brief: I never faced the problem that I can install a package, but I am not able to re-install the unchanged package. How can I solve that problem? It only affects a package which uses Rcpp - all ...
2
votes
0
answers
81
views
Minimal reproducible example package using Rcpp does not work
In short: I tried with SO and chatGPT, at some point I thought the NAMESPACE file was the error and deleted it. However, I still get an error when I run
Rcpp::compileAttributes(pkgdir = "...
0
votes
1
answer
81
views
Where should RcppEigen be in description file
I'm unsure how to only put RcppEigen under the LinkingTo and not the Imports headers. I've gotten conflicting instructions and am very confused what to do. I've been learning how to use Eigen myself, ...