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

Lisa GM ||@@|nconnect|cut @end|ng |rom gm@||@com
Sun Jun 28 20:32:25 CEST 2020


Dear Dirk,

Thank you so much for your quick reply. I'm not particularly set on the
'inline' package especially if it's becoming outdated. I looked into using
Rcpp but I couldn't figure out how to compile my c++ code outside of the
package and only include the DLL. My problem is that I cannot publish the
c++ source code with the package but I do have access to it. So I'm sorry
to ask in case this is obvious but can I compile the above to a DLL first
using Rcpp and then just add the compiled .dylib to the package?

Best,
Lisa

On Sun, Jun 28, 2020 at 7:30 PM Dirk Eddelbuettel <edd using debian.org> wrote:

>
> 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
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list