Using JuliaC from R/Python?

Hi,

Now that JuliaC.jl is released, I want to try something I’ve always wanted: being able to pass a matrix from R into Julia, have it do something, then returning a scalar/vector/matrix back into R. I’m thinking of compiling 2-3 different julia apps (one for each OS) and have them be part of my Rpackage directly.

Has anyone done this before? Just wanted to see if there’s some examples before I get into the weeds.

1 Like

Idk how R calling a shared library works but yeah it’s definitely doable, here’s an example from python FHist.jl/C_FHist/jlsum.py at C_FHist · Moelf/FHist.jl · GitHub

3 Likes

For R you probably want to consider the .Call interface from R (see the R manual “Writing R Extensions” for details). In .Call all the arguments to a C-callable function in a shared library are pointers to symbolic expressions (SEXPREC) which is the basic internal object type in R. The return value from such a function is also a pointer (SEXP) to a SEXPREC.

The code for boxing/unboxing SEXPRECs from the Julia side is currently part of the RCall package. If using JuliaC to created shared libraries of R callable functions becomes popular it may be worthwhile separating the boxing/unboxing code into its own Julia package.

2 Likes

Oh if only there is a legendary figure who knew both the dark magic of R’s internals and the light of Julia’s macros! If such a person existed… surely they will descend from the mountains and show us mortals how to tame the SEXPs and make them obey Julia’s will :folded_hands:

If only!

4 Likes

Even though I was part of R Core for twenty years it was when I started work on RCall.jl (I just started it, the majority of the development and enhancement was done by Simon and Randy) that I really began to understand the internals of R, because I could use Julia to pick apart those structures. One of the beautiful aspects of Julia is that you have so much power and flexibility available to you in a REPL.

6 Likes