Go 1.9
bachmeier via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jun 25 18:31:43 PDT 2017
On Saturday, 24 June 2017 at 23:05:58 UTC, jmh530 wrote:
> On Saturday, 24 June 2017 at 19:17:24 UTC, bachmeier wrote:
>>
>> Just this morning I got things working on Windows. Now that
>> all three major platforms have support, it is as reasonable to
>> create an R package with D functions as C, C++ or Fortran.
>> Anyone can write up a library of D functions and put a package
>> on Bitbucket or Github. The R user doesn't even need to know
>> which language the functions are written in.
>
> Music to my ears! Please put something up on announce when you
> release it.
It will probably take a while to put together a formal release.
In the meantime, you can test it if you want. Here's an example
that works for me on 64-bit Windows (it's obviously not the only
way to do this).
1. Create the D file with the functions you want to call from R.
Save this in librtest.d:
import embedr.r;
mixin(createRLibrary("rtest"));
import std.math;
export extern(C) {
Robj transform(Robj rx) {
auto x = RVector(rx);
double[] y = [log(x[0]), log(x[1])];
double result = y[0] + y[1];
return result.robj;
}
}
2. Download embedr to that same directory
https://bitbucket.org/bachmeil/embedr/raw/89797bc39030a8433839119cfcdf7de6e8d7007c/inst/embedr/r.d
3. Windows requires R.lib for compilation, so I created that by
installing the MinGW pexports.exe utility.
C:\MinGW\bin\pexports.exe R.dll > R.def
Then create the .lib using Visual Studio:
"C:\Program Files (x86)\Microsoft Visual Studio
14.0\VC\bin\lib.exe" /def:R.def /out:R.lib /machine:x64
4. Create librtest.dll using LDC:
"C:\Users\lance\ldc64\ldc2-1.3.0-beta2-win64-msvc\bin\ldmd2.exe"
-shared -m64 librtest.d r.d -version=inline R.lib
5. Open 64-bit R, load the library, and test it out:
dyn.load("librtest.dll")
.Call("transform", c(2.0, 3.0))
Disclaimer: I don't know much about Windows development. It would
be nice to have others test this out and identify problems. I
would like to figure out how to make R packages with D code on
Windows before doing a release.
More information about the Digitalmars-d
mailing list