I've been using D and R together for a decade. I wrote a blog post for the D Blog on the eve of the pandemic. I released the embedrv2 library in late 2021. It's useful for writing D functions that are called from R, using D's metaprogramming to write the necessary bindings for you.
My programs usually take the opposite approach, where D is the primary language, and I call into R to fill in missing functionality. I've accumulated a large collection of code snippets to enable all kinds of things. The problem is that they were scattered across many projects, there was no consistency across programs, documentation didn't exist, and they were more or less useless to anyone other than me.
This Github repo includes D modules, tests demonstrating most of the functionality, documentation, and some posts about how I do specific things. I'm sharing publicly all the things I've been doing in case it has value to anyone else.
Examples of functionality:
- Creating, accessing, and mutating R data structures, including vector, matrix, data frame, list, array, and time series types. Reference counting handles memory management.
- Basic statistical functionality like calculating the mean. Many of these functions use Mir for efficiency.
- Linear algebra
- Random number generation and sampling
- Parallel random number generation
- Numerical optimization: direct access to the C libraries used by R's optim function
- Quadratic programming
- Passing D functions to R without creating a shared library. For example, you can use a D function as the objective function you pass to constrOptim for constrained optimization problems.
There's more detail on the website, but I used the name "Better R" because the entirety of R is available inside your D program and you can use D to improve on it as much as you'd like. Feel free to hate the name.
I was originally going to include all of this as part of embedrv2, but realized there was almost no overlap between the two use cases. Moreover, it would be strange to call R from D and call D functions from R in the same program. It simplifies things to keep them in different projects.
If you try it and have problems, you can create a discussion. You can also post in this forum, but I won't guarantee I'll see it.