R and D interop with saucer

Lance Bachmeier no at spam.net
Tue Jan 9 21:25:30 UTC 2024


On Tuesday, 9 January 2024 at 19:56:38 UTC, data pulverizer wrote:

I'd encourage you to approach this however you like, but for the 
sake of anyone else reading this, I want to correct a few points. 
I'm guessing you haven't spent any time understanding embedrv2.

> Regarding your `R.lib` file (embedrv2 and the previous 
> version), I thought it might have something to do with Weka, 
> the machine learning library - I got my wires crossed there. 
> Perhaps I was reading something to do with the ML library 
> before/while I was reading your repo. My point still stands 
> though. I've never worked anywhere that would allow a developer 
> to install unverified pre-compiled code from an online repo. It 
> would pose too much of a security issue.

That's not "unverified pre-compiled code". As I said, it's an 
import library for Windows, from an attempt long ago to call R 
from D on Windows. You don't call the .dll file directly on 
Windows, you call the .lib file. It's the same thing you do with 
OpenBLAS and many other popular libraries.

> As I explained my approach is to mirror the 'design language' 
> of Rcpp/RInside/cpp11 libraries, because its a great approach, 
> I'm familiar with it, and so are many others. A user (including 
> myself) will be sensitive to on-boarding and usage friction, so 
> I my library will present a clear, familiar, and easy to use 
> interface.

I'm familiar with Rcpp/RInside/cpp11. If you go to the CRAN page 
for RInside, you'll see I'm one of the authors. If you check out 
Dirk's 2013 book, you'll see that one of the sections in it was 
based on an example I gave him. I haven't done much with cpp11, 
but that's because I was already using D before it existed. 
embedrv2 does exactly the same thing. You write your D function 
and metaprogramming is used to create a wrapper that you can call 
from R without further modification.

> I didn't know about your betterr R package. I think it is a 
> different approach from the one I would take. I think both Rcpp 
> and in particular cpp11 have very good design approaches and 
> continuous improvements to their design that gives me plenty to 
> think about. They are at the cutting edge and are pushing the 
> boundaries, and I think it would be cool to show that D can 
> play in the same space with ease, finesse, and style.

Since you've clearly never used it and don't know how it works, 
why are you trashing it? I'll let anyone else judge how awkward, 
complicated and lacking in style it is. Here's the example from 
the landing page:

```
void main() {
   // Initialization
   startR();
   // Generate 100 draws from a N(0.5, sd=0.1) distribution
   Vector x = rnorm(100, 0.5, 0.1);
   // Create a 3x2 matrix and fill the columns
   auto m = Matrix(3,2);
   Column(m,0) = [1.1, 2.2, 3.3];
   Column(m,1) = [4.4, 5.5, 6.6];
   // Calculate the inverse of the transpose
   auto m2 = solve(t(m));
   // Modify the second and third elements of the first column of m
   m[1..$,0] = [7.7, 8.8];
   // Choose x and y to minimize x^2 + y^2
   // Use Nelder-Mead with initial guesses 3.5 and -5.5
   auto nm = NelderMead(&f);
   OptimSolution sol = nm.solve([3.5, -5.5]);
   // Clean up
   closeR();
}

extern(C) {
   double f(int n, double * par, void * ex) {
     return par[0]*par[0] + par[1]*par[1];
   }
}
```

That's ten lines of code to generate a vector of random numbers, 
create and fill a matrix, take the inverse of the transpose of 
the matrix, mutate the matrix, and solve a nonlinear optimization 
problem.

I don't care that you're not using it. Have fun creating your own 
project. That doesn't excuse writing falsehoods about the work 
I've done.



More information about the Digitalmars-d-announce mailing list