# Developing an R package using Julia for a statistical model

**URL:** <https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320>\
**Category:** Statistics\
**Created:** [October 15, 2024, 8:56am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320 "2024-10-15T08:56:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mateus\_Maia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mateus_maia/32/212651_2.png) [@Mateus\_Maia](https://discourse.julialang.org/u/Mateus_Maia)\
**Post date:** [October 15, 2024, 8:56am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/1 "2024-10-15T08:56:31Z")

</div>

Hi all,

I would like to know what is the current state of using Julia as a backend for an R package. I writing a code for a statistical model, but I aware that most of the people will use R to run those analysis so I would like to know if is possible now days to have a R package with Julia running in the backend.

If is not possible, at the moment so it might not be worth the pay off of trying to implement in Julia from the scratch.

Thank you all,

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 15, 2024, 8:58am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/2 "2024-10-15T08:58:12Z")

</div>

There was some development of compiling Julia code to small binaries which R can then call. It was in another thread. I expect to see development over the next 2 years or so

---

<div class="post-metadata">

**Author:** ![Mateus\_Maia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mateus_maia/32/212651_2.png) [@Mateus\_Maia](https://discourse.julialang.org/u/Mateus_Maia)\
**Post date:** [October 15, 2024, 9:05am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/3 "2024-10-15T09:05:54Z")

</div>

yes, most of the things that are so are more related with small chunks of code being generated in R, but nothing like could be used in a R package

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [October 15, 2024, 9:18am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/4 "2024-10-15T09:18:43Z")

</div>

I don’t know much about R but there is a rather high-profile Python package for symbolic regression which is just a front end for Julia:

> **[GitHub - MilesCranmer/PySR: High-Performance Symbolic Regression in Python and...](https://github.com/MilesCranmer/PySR)**
>
> High-Performance Symbolic Regression in Python and Julia

Maybe @MilesCranmer would know some R equivalents

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 15, 2024, 9:20am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/5 "2024-10-15T09:20:06Z")

</div>

There is at least one differential equation solver available in r that is entirely based on Julia

Julia will become like rcpp in a few years

---

<div class="post-metadata">

**Author:** ![Mateus\_Maia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mateus_maia/32/212651_2.png) [@Mateus\_Maia](https://discourse.julialang.org/u/Mateus_Maia)\
**Post date:** [October 15, 2024, 9:27am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/6 "2024-10-15T09:27:03Z")

</div>

Do you have the link of this diff. equation solver package? I would be interested and would be very useful if I can explore the git repository

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [October 15, 2024, 9:36am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/7 "2024-10-15T09:36:55Z")

</div>

[GitHub - SciML/diffeqr: Solving differential equations in R using DifferentialEquations.jl and the SciML Scientific Machine Learning ecosystem](https://github.com/SciML/diffeqr)?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 15, 2024, 11:23am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/8 "2024-10-15T11:23:03Z")

</div>

Yeah. I found it by googline “differential equation solver r package coded in julia”

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [October 15, 2024, 12:37pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/9 "2024-10-15T12:37:23Z")

</div>

> [@gdalle](#):
>
> there is a rather high-profile Python package symbolic regression which is just a front end for Julia

What’s their approach to Julia installation? Is it handled within `pip` or `conda` on the Python side?

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [October 15, 2024, 12:39pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/10 "2024-10-15T12:39:21Z")

</div>

I think everything is handled with this dual Julia/Python binding package:

> **[GitHub - JuliaPy/PythonCall.jl: Python and Julia in harmony.](https://github.com/JuliaPy/PythonCall.jl)**
>
> Python and Julia in harmony.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 15, 2024, 12:42pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/11 "2024-10-15T12:42:13Z")

</div>

It’s already possible to call Julia from R (as other have suggested for package development), and done, and note also RCall.jl for calling in other direction, with its R mode.

Note also:

> [@Julia as a universal platform for statistical software development](https://discourse.julialang.org/t/julia-as-a-universal-platform-for-statistical-software-development/113017):
>
> I just posted [a paper](https://arxiv.org/abs/2404.09309) presenting a vision of using Julia as a universal back end for statistical software development. Do things once in Julia–optimize, maintain, add features–then call from R or Python or Matlab or Stata. The motivating example is my pair of packages for Stata, which is a commercial statistics program that is popular in the social sciences and elsewhere. julia provides a C-based bridge from Stata to Julia, like JuliaCall for R. It has routines for fast data copying and provide…

And upcoming `juliac` compiler will likely make this even more compelling, but it’s strictly not needed, current tools good enough.

> I think everything is handled with this dual Julia/Python binding package

That PythonCall package is of course Python specific, but it relies on CondaPkg.jl which isn’t. I’m not sure, maybe, probably, it helps for R users installing Julia dependencies?

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [October 15, 2024, 2:36pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/12 "2024-10-15T14:36:41Z")

</div>

See [this thread.](https://discourse.julialang.org/t/pushing-the-limits-of-small-binary-creation/120989) With the work that has gone into small binary compilation of Julia code, it now seems possible to create a dynamic library that you can just call in R. You may want to reach out to the authors there to see if you can help with this.

---

<div class="post-metadata">

**Author:** ![droodman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/droodman/32/26652_2.png) [@droodman](https://discourse.julialang.org/u/droodman)\
**Post date:** [October 15, 2024, 5:10pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/13 "2024-10-15T17:10:55Z")

</div>

As described in that paper, the R package fwildclusterboot uses the Julia package WildBootTests.jl as a back end. For some problems the Julia backend is optional (but faster). For others, it is required. The Stata package boottest can use the same back end.

For sure, once juliac is more official, I’ll try to move to that so that users need not install Julia.

---

<div class="post-metadata">

**Author:** ![viralbshah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/viralbshah/32/54_2.png) [@viralbshah](https://discourse.julialang.org/u/viralbshah)\
**Post date:** [October 15, 2024, 9:51pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/14 "2024-10-15T21:51:56Z")

</div>

> [@xiaodai](#):
>
> There was some development of compiling Julia code to small binaries which R can then call. It was in another thread. I expect to see development over the next 2 years or so

I am expecting `juliac` built small binaries to work for this purpose by Julia 1.12, but no later than Julia 1.13. Probably, we’ll need some tooling to then make it all work well together.

-viral

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 15, 2024, 10:33pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/15 "2024-10-15T22:33:52Z")

</div>

> [@droodman](#):
>
> I’ll try to move to that so that users need not install Julia.

Note:  
[https://cran.r-project.org/web/packages/JuliaCall/readme/README.html](https://cran.r-project.org/web/packages/JuliaCall/readme/README.html)

> Or you can do
> 
> ```julia
> library(JuliaCall)
> julia_setup(installJulia = TRUE)
> 
> ```
> 
> which will invoke install\_julia automatically if Julia is not found and also do initialization of JuliaCall.

I don’t know if there are any problems, if it’s as smooth as calling Julia from Python (PythonCall.jl can also install Python automatically) using that other package with same name:

> JuliaCall manages its Julia dependencies using JuliaPkg. It will automatically download a suitable version of Julia if required.

> [@droodman](#):
>
> the R package fwildclusterboot uses the Julia package [WildBootTests.jl](https://juliahub.com/ui/Packages/General/WildBootTests) as a back end.

I’m not sure why…:  
[https://cran.r-project.org/web/packages/fwildclusterboot/index.html](https://cran.r-project.org/web/packages/fwildclusterboot/index.html)

> Package ‘fwildclusterboot’ was removed from the CRAN repository.  
> Formerly available versions can be obtained from the archive.[that’s a link at target, that didn’t copy-paste.]  
> Archived on 2024-05-29 as issues were not corrected in time.

[Note, in Julia you can’t remove packages from the index, that would be a security irsk, as happened for JavaScript…]

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 15, 2024, 11:00pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/16 "2024-10-15T23:00:38Z")

</div>

Yeah. I was think something more akin to Rcpp in R

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 15, 2024, 11:01pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/17 "2024-10-15T23:01:41Z")

</div>

> [@Palli](#):
>
> ```julia
> library(JuliaCall)
> julia_setup(installJulia = TRUE)
> 
> ```

This is often a problem in corporate environments because install stuff off the net is not allowed. So need something more suited

---

<div class="post-metadata">

**Author:** ![droodman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/droodman/32/26652_2.png) [@droodman](https://discourse.julialang.org/u/droodman)\
**Post date:** [October 16, 2024, 12:11am UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/18 "2024-10-16T00:11:50Z")

</div>

Yes, as @ [xiaodai](https://discourse.julialang.org/u/xiaodai) says, while ideally Julia installation should be smooth as butter, dependence on it is still a source of fragility. More things can go wrong if Julia is required than if you can just deliver a shared library to the user’s file store. There may also be some speed benefit, at least the first time the library is called in a session.

fwildclusterboot uses the JuliaCall package you referenced, or some comparable package.

---

<div class="post-metadata">

**Author:** ![rcqls](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rcqls/32/210708_2.png) [@rcqls](https://discourse.julialang.org/u/rcqls)\
**Post date:** [December 5, 2024, 2:37pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/19 "2024-12-05T14:37:42Z")

</div>

Hi, I am in the process to develop [Rulia](https://github.com/rcqls/Rulia) to make some R package “wrapping” julia package. It is an alternative of JuliaCall which depends on Rcpp. My goal is to replace C++ by Julia to boost R code.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [December 5, 2024, 2:56pm UTC](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320/20 "2024-12-05T14:56:10Z")

</div>

I think nobody highlighted that there are 2 very different approaches to the problem:

1. On one side an R package can depend on JuliaCall and when installed, it can install Julia and the desired Julia package that it wraps in the background. This I believe is the approach taken by current R wrappers to Julia packages.
2. On the other side, the Julia package can be “compiled” in an lib/executable and the R package interface this directly (using the C API ??). This is way more “frontier” approach. For example, the “compilation” of a Julia package in a small binary that doesn’t take everything with it has been only very recently added to Julia 1.12(that still needs to be released…).

[Next page](https://discourse.julialang.org/t/developing-an-r-package-using-julia-for-a-statistical-model/121320.md?page=2)
