Linking R and Julia?

2019-01-29 18:00发布

Julia looks very promising for fast and syntax-sane computation (e.g. here), but I suspect it will not be anywhere near R in terms of overall statistics workflow for some time yet. So I'd like to use it where C++ is mainly used in R programs: to optimize slow portions of code. Before I invest the time in learning Julia, though, I am curious what facilities there are for embedding Julia snippets in R code.

So:

  • What facilities are out there for linking R and Julia?
  • How robust and well-thought-out are they, on a scale of zero to Rcpp?

I want to call Julia from R, just as Rcpp allows calling C++ from within R right now. I do not want to call R from Julia. (So RCall.jl would not work)

标签: r julia-lang
7条回答
叛逆
2楼-- · 2019-01-29 18:49

I create an R package called JuliaCall recently, which embeds Julia in R. The package is on CRAN.

https://cran.r-project.org/web/packages/JuliaCall/index.html

https://github.com/Non-Contradiction/JuliaCall

The usage of the package is like this:

library(JuliaCall)
julia <- julia_setup()
julia_command("a = sqrt(2)"); julia_eval("a")
julia_eval("sqrt(2)")
julia_call("sqrt", 2)
julia_eval("sqrt")(2)

As you can see, you could send command strings and call Julia functions really easily.

And there are also some R packages wrapping Julia packages using JuliaCall, for example,

  • convexjlr for Disciplined Convex Programming in R using Convex.jl, which is also on CRAN.
  • ipoptjlr, an R Interface for Interior Point OPTimizer (IPOPT) using Julia package Ipopt.jl.

Welcome for any feedback on JuliaCall!!

查看更多
登录 后发表回答