I am converting this R function into C++ function using Rcpp
package. However, since rdiscrete()
function is from e1071
package, I am struggling to loading the existing R package and calling the functions from this package.
R function (works fine):
library(e1071)
signR <- function(x) {
if (x >= 0) {
rdiscrete(10,c(0.2,0.8),c(5,6))
} else {
rdiscrete(10,c(0.2,0.8),c(1,2))
}
}
## Example
signR(2)
Rcpp version (error pointed to rdiscrete
function):
library(Rcpp)
cppFunction('int signC(int x) {
if (x >= 0) {
return rdiscrete(10,c(0.2,0.8),c(5,6));
} else {
return rdiscrete(10,c(0.2,0.8),c(1,2));
}
}')
I appreciate any replies in advance!