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

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


One can do what you do, but it is fraught with some difficulties (as you
experienced) and even more so once you try to do this portably. Helper
packages exists: the `inline` package is the oldest of this class and still
supports the .C() interface you used here. And which for a few years now has
generally been recommended against.  But if you insist, you can; and `inline`
will take care of compiling, linking and loading for you.

But you already use C++ as evidenced by the iostream use. So why not use just
a wee bit more of it?  It makes you program simpler (one less argument on the
signature) and opens the door to more tooling--in the snippet below we use
Rcpp without using any of its data types. It even runs the R example for us.

Code first:
#include <Rcpp.h>

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

/*** R
myvec <- sqrt(1:10)
sum(77, myvec)

Usage demo:
R> Rcpp::sourceCpp("/tmp/lisademo.cpp")

R> myvec <- sqrt(1:10)

R> sum(77, myvec)
[1] 99.4683

There are other helper packages, and if you still want to do it by hand all
details are in _Writing R Extensions_.


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

More information about the R-package-devel mailing list