Skip to content

Instantly share code, notes, and snippets.

@frankier
Created September 16, 2023 08:12
Show Gist options
  • Save frankier/0ac468305f8b04d98c90551eda0da15d to your computer and use it in GitHub Desktop.
Save frankier/0ac468305f8b04d98c90551eda0da15d to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
rm -rf testproj
mkdir -p testproj
# Default Conda
R_HOME="*" julia --project=testproj -e "using Pkg; Pkg.develop(path=\"$RCALL_PATH\"); Pkg.build(\"RCall\")"
julia --project=testproj -e 'using Pkg; Pkg.add(["CondaPkg", "Libdl", "PreferenceTools"])'
echo "Should be Conda R"
julia --project=testproj -e 'using RCall; print(RCall.libR)'
# CondaPkg
cat > testproj/CondaPkg.toml << 'EOF'
[deps]
r = ""
EOF
cat > testproj/setup_rcondapkg.jl << 'EOF'
using CondaPkg
using Preferences
using Libdl
using PreferenceTools
function locate_libR(Rhome)
@static if Sys.iswindows()
libR = joinpath(Rhome, "bin", Sys.WORD_SIZE==64 ? "x64" : "i386", "R.dll")
else
libR = joinpath(Rhome, "lib", "libR.$(Libdl.dlext)")
end
return libR
end
CondaPkg.resolve()
target_rhome = "$(CondaPkg.envdir())/lib/R"
PreferenceTools.add(
"RCall",
"Rhome" => target_rhome,
"libR" => locate_libR(target_rhome)
)
EOF
julia --project=testproj testproj/setup_rcondapkg.jl
echo "Should be CondaPkg R"
julia --project=testproj -e 'using RCall; print(RCall.libR)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment