I have the following cumsum_bounded.cpp file
#include <Rcpp.h>
using namespace Rcpp;
NumericVector cumsum_bounded(NumericVector x, double low, double high) {
NumericVector res(x.size());
double acc = 0;
for (int i=0; i < x.size(); ++i) {
acc += x[i];
if (acc < low) acc = low;
else if (acc > high) acc = high;
res[i] = acc;
}
return res;
}
Then I create and overwrite and test my new function.
cumsum_bounded(c(1, -2, 3), low = 2, high = 10)
[1] 1 0 3
Then I create the documentation.
devtools::document()
When I Build & Reloadcompile everything fine.
But when I run cumsum_bounded(c(1, 2, 3), low= 2, high = 10), I get an error:
Error in .Call("joshr_cumsum_bounded", PACKAGE = "joshr", x, low, high) :
"joshr_cumsum_bounded" not available for .Call() for package "joshr"
NAMESPACE
export(cumsum_bounded)
Update:
If I create a new project as described above and DO NOT use the function Build & Reload, but devtools :: loadall (), it will work. But as soon as I press this button Build & Reload, it goes sideways.
source
share