0

I have a package, https://github.com/tfrostig/RSEE, which includes a few (3) RcppArmadillo functions. The package works well on other computer. When I build the package no errors appear, but whenever I call any of the RCPP functions it causes R to crash.

When I try to use my Unit Testing, I obtain the error: "Exited with status -1073741819" .

If I use Rcpp::sourceCpp() and then call the functions, everything works well. Other packages with Rcpp functions work well.

For example:

`// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
using namespace arma;


// [[Rcpp::export]]
arma::mat localRegression(arma::mat weightmat, arma::mat modelmat, arma::vec xtemp) {
  return inv(modelmat.t() * weightmat * modelmat) * modelmat.t() * weightmat * xtemp;
}

Using RSEE:::localRegression will cause it to crash. If I load the source code using sourceCpp and then call localRegression it works ok.

What can cause this type of problem?

The session info is: 
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_Israel.1252  LC_CTYPE=English_Israel.1252    LC_MONETARY=English_Israel.1252
[4] LC_NUMERIC=C                    LC_TIME=English_Israel.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RSEE_0.1.0

loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3    Rcpp_1.0.6    
Kozolovska
  • 1,090
  • 6
  • 14

1 Answers1

5

Taking a look at your package, I am assuming that the error and crash comes from arma::mat iterLowess(..., double epsmed = 10^(-6)) { in src/RCPP_LOWESS.cpp. Note that ^ is not a power operation in Cpp, but instead a byte XOR operation. Furthermore 10 is an integer while 10.0 is a double, so while the compiler "should" do automatic conversion it might simply fail.

Try for example

library(Rcpp)
f <- cppFunction('double powww(double x = 10^(-6)){
                 double y = x^2;
                 return y;}')

and you'll notice this throws an error.

It is almost impossible to give you an exact answer, as we have very limited information in the question, but since you mention it crashes immediately upon calling the function (I'm assuming it does so in the debugging state as well) we should be looking at the function definition for our error.

Oliver
  • 8,169
  • 3
  • 15
  • 37
  • Thanks! It worked, the crash happened when I called each of the Rcpp functions but after applying your advice it works.. Do you know what causes it to work on one computer and not on the other? Also, how did it compile ok using Rcpp::sourceCpp? – Kozolovska Feb 15 '21 at 10:35
  • 1
    If you really mean 2 different computers, it is likely a difference in compiler (either version or type) or maybe operating system. Maybe `clang-c++` will actually handle this error (which would I assume lead to unintended behaviour) while another compiler such as Gcc or MVSC++ would not. Maybe version 8 of gcc handles it? Who knows. One would require more information, before we could even ordain to make a guess why this is the case. :-) – Oliver Feb 15 '21 at 10:40