JuliaInterop / JuliaCall

Embed Julia in R
https://non-contradiction.github.io/JuliaCall/index.html
Other
267 stars 36 forks source link

Compilation error - DifferentialEquations.jl / "could not load library libopenlibm" #103

Closed waidschrat closed 5 years ago

waidschrat commented 5 years ago

Hi, I just discovered your great package (thanks for that) and tried to replicate a comparably simple function call using DifferentialEquations.jl that was successful with the XRJulia package. JuliaCall, however, keeps throwing an error. Do you have any ideas how to solve this issue? Best, Bob

Errormsg: Error: Error happens in Julia. error compiling handle_dt!: error compiling ode_determine_initdt: could not load library "libopenlibm"

Code:

code <- "
function ODEfun(u0, p)
  function lotka_volterra(du,u,p,t)
    x, y = u
    alpha, beta, delta, gamma = p
    du[1] = dx = alpha*x - beta*x*y
    du[2] = dy = -delta*y + gamma*x*y
  end
  tspan = (0.0,10.0)
  prob = ODEProblem(lotka_volterra,u0,tspan,p)
  solve(prob)
end
"

library(JuliaCall)
julia_library("DifferentialEquations")
ODEsol <- julia_eval(code)
ODEsol(c(1.0,4.0), c(1.5,1.0,3.0,1.0))
Session Info ```r R version 3.6.0 (2019-04-26) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17134) Matrix products: default locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5] LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] JuliaCall_0.16.5 deSolve.jl_0.1.0 deSolve_1.21 XRJulia_0.9.0 usethis_1.5.0 devtools_2.0.2 loaded via a namespace (and not attached): [1] Rcpp_1.0.1 rstudioapi_0.10 knitr_1.22 magrittr_1.5 pkgload_1.0.2 R6_2.4.0 rlang_0.3.4 [8] XR_0.7.2 tools_3.6.0 pkgbuild_1.0.3 packrat_0.5.0 xfun_0.6 sessioninfo_1.1.1 cli_1.1.0 [15] withr_2.1.2 remotes_2.0.4 assertthat_0.2.1 digest_0.6.18 rprojroot_1.3-2 crayon_1.3.4 processx_3.3.0 [22] callr_3.2.0 fs_1.3.0 ps_1.3.0 testthat_2.1.1 memoise_1.1.0 glue_1.3.1 compiler_3.6.0 [29] desc_1.2.0 backports_1.1.4 prettyunits_1.0.2 jsonlite_1.6 ```
Non-Contradiction commented 5 years ago

Thanks for the feedback!

It seems that JuliaCall fails to locate the position of libopenlibm. I have an idea to fix the problem. How about trying

using Libdl
print(Libdl.dlpath(Base.libm_name))

in Julia, and then dyn.load("the file name returned from the previous Julia command") in R before using JuliaCall?

If this works, then I will incorporate the change into the development version of JuliaCall.

waidschrat commented 5 years ago

works like a charm, thank you