I built a dummy Rcpp package using Rcpp.package.skeleton(myPackage)
with a single function:
// [[Rcpp::export]]
double triple_balance(const double& balance) {
if(R_IsNA(balance)) {
stop("balance is NA, please provide a numeric value");
} else {
double result = balance*3;
return result;
}
}
In unit tests, I want to make sure that the function returns an error when a wrong input is passed, which it consistently does if I source it:
Rcpp::sourceCpp('src/triple_balance.cpp')
triple_balance("10")
Error in triple_balance("10") : Not compatible with requested type: [type=character; target=double].
However, if I Install and Restart the package, running triple_balance("10")
crashes RStudio. I should add that the crash does not happen every time and it seems to depend on the initial state of the library, e.g. whether I installed previous versions of the package before, for example with or without const
in the function definition.
What could explain such an inconsistent behaviour?
My sessionInfo
:
> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.8 (Maipo)
Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rcppDummy_1.0
loaded via a namespace (and not attached):
[1] compiler_3.6.0 tools_3.6.0 Rcpp_1.0.2 packrat_0.5.0