I have the following file cumsum_bounded.cpp
#include <Rcpp.h>
using namespace Rcpp;
//' Cumulative sum.
//' @param x numeric vector
//' @param low lower bound
//' @param high upper bound
//' @param res bounded numeric vector
//' @export
//' @return bounded numeric vector
// [[Rcpp::export]]
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;
}
I then Build & Reload and test out my new function.
cumsum_bounded(c(1, -2, 3), low = 2, high = 10)
[1] 1 0 3
Then I build the documentation.
devtools::document()
When I Build & Reload
everything compiles fine.
But when I run cumsum_bounded(c(1, 2, 3), low= 2, high = 10)
I get the error:
Error in .Call("joshr_cumsum_bounded", PACKAGE = "joshr", x, low, high) :
"joshr_cumsum_bounded" not available for .Call() for package "joshr"
NAMESPACE
# Generated by roxygen2: do not edit by hand
export(cumsum_bounded)
Update:
If I create a new project as above and DON'T use the Build & Reload
function but rather devtools::loadall(), it will work. But once I press that Build & Reload
button, it goes sideways.
document()
? – Roxieroxinedevtools
-- asRcpp
itself works as documented. And we don't say anything (good or bad) aboutdevtools
. I would just runRcpp::compileAttributes()
the the very fine manual says. – ReprehendBuild & Reload
button executesRcpp::compileAttributes()
. – Chickadeecumsum_bounded.Rd
– Chickadeedevtools
out and do File -> New Project to select 'Create a Package' and select Rcpp. It. Will. Just. Work. Then add your code. – Reprehendjoshr::cumsum_bounded(c(1, 2, 3), low= 2, high = 10)
? – KareykariNAMESPACE
file? – Kareykari