Skip to content

Commit

Permalink
Allow installing package without R installation
Browse files Browse the repository at this point in the history
This is in case the user wants to specify and installation via
Preferences.jl after installation. An error message is printed at import
time if no installation is available.
  • Loading branch information
frankier committed Aug 14, 2023
1 parent 85fd3a4 commit 187a921
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
29 changes: 22 additions & 7 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ try
@info "Using previously configured R at $Rhome with libR in $libR."
else
Rhome = get(ENV, "R_HOME", "")
libR = nothing
if Rhome == "*"
# install with Conda
@info "Installing R via Conda. To use a different R installation,"*
Expand Down Expand Up @@ -54,16 +55,30 @@ try
end
end

isempty(Rhome) && error("R cannot be found. Set the \"R_HOME\" environment variable to re-run Pkg.build(\"RCall\").")
libR = locate_libR(Rhome)
if !isempty(Rhome)
libR = locate_libR(Rhome)
end
end

@info "Using R at $Rhome and libR at $libR."
if DepFile.Rhome != Rhome || DepFile.libR != libR
if isempty(Rhome)
@info (
"No R installation found. " *
"You will not be able to import RCall without " *
"providing values for its preferences Rhome and libR."
)
open(depfile, "w") do f
println(f, "const Rhome = \"", escape_string(Rhome), '"')
println(f, "const libR = \"", escape_string(libR), '"')
println(f, "const conda_provided_r = $(conda_provided_r)")
println(f, "const Rhome = nothing")
println(f, "const libR = nothing")
println(f, "const conda_provided_r = nothing")
end
else
@info "Using R at $Rhome and libR at $libR."
if DepFile.Rhome != Rhome || DepFile.libR != libR
open(depfile, "w") do f
println(f, "const Rhome = \"", escape_string(Rhome), '"')
println(f, "const libR = \"", escape_string(libR), '"')
println(f, "const conda_provided_r = $(conda_provided_r)")
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions src/RCall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ else
const depfile = joinpath(dirname(@__FILE__),"..","deps","deps.jl")
if isfile(depfile)
include(depfile)
if Rhome === nothing
error(
"No R installation was detected as RCall installation time. " *
"Please provided the location of R by setting the Rhome and libR preferences or " *
"else set R_HOME='*' and rerun Pkg.build(\"RCall\") to use Conda.jl."
)
end
else
error("RCall not properly installed. Please run Pkg.build(\"RCall\")")
end
Expand Down

0 comments on commit 187a921

Please sign in to comment.