On 6/29/23 7:51 PM, bachmeier wrote:
I've been using D and R together for a decade. I wrote [a blog post for
the D
Blog](https://dlang.org/blog/2020/01/27/d-for-data-science-calling-r-from-d/) on the eve of the pandemic. I released the [embedrv2 library](https://github.com/bachmeil/embedrv2) 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](https://github.com/bachmeil/betterr) 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.
[Project website](https://bachmeil.github.io/betterr/)
This is very cool! I've never used R, but I have wanted to learn more
about such languages.
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.
Awfull, awfull name...
-Steve