Skip to content

Commit d5197b8

Browse files
author
Frankie Robertson
committed
Switch to using Preferences-based RCall
1 parent f9df886 commit d5197b8

File tree

6 files changed

+61
-14
lines changed

6 files changed

+61
-14
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
R_HOME: '*'
7474
- name: Make docs
7575
run: |
76-
julia --project=docs/ docs/setup_r.jl &&
76+
julia --project=docs/ docs/fix_r_preferences.jl &&
7777
USE_CAIRO_MAKIE=1 julia --project=docs/ -e '
7878
include("docs/make.jl")'
7979
env:

docs/Manifest.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,9 @@ version = "0.2.19"
15221522

15231523
[[deps.RCall]]
15241524
deps = ["CategoricalArrays", "Conda", "DataFrames", "DataStructures", "Dates", "Libdl", "Missings", "REPL", "Random", "Requires", "StatsModels", "WinReg"]
1525-
git-tree-sha1 = "d441bdeea943f8e8f293e0e3a78fe2d7c3aa24e6"
1525+
git-tree-sha1 = "c0cbc8173a6782e19df785a6a12ddfd9e0c31ca7"
1526+
repo-rev = "master"
1527+
repo-url = "https://github.com/frankier/RCall.jl.git#preferences-r-installation"
15261528
uuid = "6f49c342-dc21-5d91-9882-a32aef131414"
15271529
version = "0.13.15"
15281530

docs/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
julia --project=. ./setup_r.jl
3+
julia --project=. ./fix_r_preferences.jl
44
USE_CAIRO_MAKIE=1 julia --project=. make.jl

docs/fix_r_preferences.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using CondaPkg
2+
using Preferences
3+
using Libdl
4+
using PreferenceTools
5+
6+
"""
7+
validate_libR(libR)
8+
9+
Checks that the R library `libR` can be loaded and is satisfies version requirements.
10+
11+
"""
12+
function validate_libR(libR)
13+
if !isfile(libR)
14+
error("Could not find library $libR. Make sure that R shared library exists.")
15+
end
16+
# Issue #143
17+
# On linux, sometimes libraries linked from libR (e.g. libRblas.so) won't open unless LD_LIBRARY_PATH is set correctly.
18+
libptr = try
19+
Libdl.dlopen(libR)
20+
catch er
21+
Base.with_output_color(:red, stderr) do io
22+
print(io, "ERROR: ")
23+
showerror(io, er)
24+
println(io)
25+
end
26+
@static if Sys.iswindows()
27+
error("Try adding $(dirname(libR)) to the \"PATH\" environmental variable and restarting Julia.")
28+
else
29+
error("Try adding $(dirname(libR)) to the \"LD_LIBRARY_PATH\" environmental variable and restarting Julia.")
30+
end
31+
end
32+
# R_tryCatchError is only available on v3.4.0 or later.
33+
if Libdl.dlsym_e(libptr, "R_tryCatchError") == C_NULL
34+
error("R library $libR appears to be too old. RCall.jl requires R 3.4.0 or later.")
35+
end
36+
Libdl.dlclose(libptr)
37+
return true
38+
end
39+
40+
function locate_libR(Rhome)
41+
@static if Sys.iswindows()
42+
libR = joinpath(Rhome, "bin", Sys.WORD_SIZE==64 ? "x64" : "i386", "R.dll")
43+
else
44+
libR = joinpath(Rhome, "lib", "libR.$(Libdl.dlext)")
45+
end
46+
validate_libR(libR)
47+
return libR
48+
end
49+
50+
CondaPkg.resolve()
51+
target_rhome = "$(CondaPkg.envdir())/lib/R"
52+
PreferenceTools.add(
53+
"RCall",
54+
"Rhome" => target_rhome,
55+
"libR" => locate_libR(target_rhome)
56+
)

docs/make.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
include("./setup_r.jl")
2-
31
using ComputerAdaptiveTesting
42
using CATPlots
53

docs/setup_r.jl

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)