[R-pkg-devel] R package does not find DLL routine

Dirk Eddelbuettel edd @end|ng |rom deb|@n@org
Sun Jun 28 18:54:43 CEST 2020


Lisa,

Sorry, I misread your code. There is a possible array overrun, so we need
argument n and p, apparently.  A likely better version, and demo running the
right code are below.  The rest of the reasoning likely stands, methinks.

Code
-----------------------------------------------------------------------------
#include <Rcpp.h>

// [[Rcpp::export]]
void mysum(int p, int n, std::vector<double> array) {
  double res = 0;
  int myend = std::min(p * n, (int)array.size());
  for (int i = 0; i < myend; ++i) {
    res += array[i];
  }
  std::cout << "result : " << res << std::endl;
}

/*** R
myvec <- sqrt(1:10)
mysum(2,3,myvec)
*/
-----------------------------------------------------------------------------

Demo usage
-----------------------------------------------------------------------------
R> Rcpp::sourceCpp("/tmp/lisademo.cpp")

R> myvec <- sqrt(1:10)

R> mysum(2,3,myvec)
result : 10.8318
R> 
-----------------------------------------------------------------------------

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org



More information about the R-package-devel mailing list