Skip to content

Commit

Permalink
Only run __init__ when not precompling
Browse files Browse the repository at this point in the history
  • Loading branch information
frankier committed Aug 14, 2023
1 parent 3a41025 commit 30f51d9
Showing 1 changed file with 45 additions and 42 deletions.
87 changes: 45 additions & 42 deletions src/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,56 +173,59 @@ include(joinpath(dirname(@__FILE__),"..","deps","setup.jl"))
currently_compiling() = ccall(:jl_generating_output, Cint, ()) != 0

function __init__()
if !currently_compiling() && Rhome == ""
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
validate_libR(libR)

# Check if R already running
# for some reaons, cglobal((:R_NilValue, libR)) doesn't work on rstudio/linux
# https://github.com/Non-Contradiction/JuliaCall/issues/34
Rinited, from_libR = try
unsafe_load(cglobal(:R_NilValue, Ptr{Cvoid})) != C_NULL, false
catch
unsafe_load(cglobal((:R_NilValue, libR), Ptr{Cvoid})) != C_NULL, true
end
if !currently_compiling()
if Rhome == ""
error(

Check warning on line 178 in src/setup.jl

View check run for this annotation

Codecov / codecov/patch

src/setup.jl#L178

Added line #L178 was not covered by tests
"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

if !Rinited
initEmbeddedR()
end
validate_libR(libR)

ip = ccall((:Rf_ScalarInteger, libR),Ptr{Cvoid},(Cint,),0)
# Check if R already running
# for some reaons, cglobal((:R_NilValue, libR)) doesn't work on rstudio/linux
# https://github.com/Non-Contradiction/JuliaCall/issues/34
Rinited, from_libR = try
unsafe_load(cglobal(:R_NilValue, Ptr{Cvoid})) != C_NULL, false
catch
unsafe_load(cglobal((:R_NilValue, libR), Ptr{Cvoid})) != C_NULL, true
end

Const.load(from_libR)
if !Rinited
initEmbeddedR()
end

# set up function callbacks
setup_callbacks()
ip = ccall((:Rf_ScalarInteger, libR),Ptr{Cvoid},(Cint,),0)

if !Rinited
# print warnings as they arise
# we can't use Rf_PrintWarnings as not exported on all platforms.
rcall_p(:options,warn=1)
Const.load(from_libR)

# disable menu on windows
rcall_p(:options; Symbol("menu.graphics") => false)
# set up function callbacks
setup_callbacks()

# R gui eventloop
isinteractive() && rgui_init()
end
if !Rinited
# print warnings as they arise
# we can't use Rf_PrintWarnings as not exported on all platforms.
rcall_p(:options,warn=1)

@require AxisArrays="39de3d68-74b9-583c-8d2d-e117c070f3a9" begin
include("convert/axisarray.jl")
end
# disable menu on windows
rcall_p(:options; Symbol("menu.graphics") => false)

# R gui eventloop
isinteractive() && rgui_init()
end

# R REPL mode
isdefined(Base, :active_repl) &&
isinteractive() && typeof(Base.active_repl) != REPL.BasicREPL &&
!RPrompt.repl_inited(Base.active_repl) && RPrompt.repl_init(Base.active_repl)
@require AxisArrays="39de3d68-74b9-583c-8d2d-e117c070f3a9" begin
include("convert/axisarray.jl")
end

# R REPL mode
isdefined(Base, :active_repl) &&
isinteractive() && typeof(Base.active_repl) != REPL.BasicREPL &&
!RPrompt.repl_inited(Base.active_repl) && RPrompt.repl_init(Base.active_repl)

# # IJulia hooks
isdefined(Main, :IJulia) && Main.IJulia.inited && ijulia_init()
# # IJulia hooks
isdefined(Main, :IJulia) && Main.IJulia.inited && ijulia_init()
end
end

0 comments on commit 30f51d9

Please sign in to comment.