armgong / rjulia

R package which integrating R and Julia
GNU General Public License v2.0
146 stars 23 forks source link

Error after installing Julia packages #59

Closed pcarbo closed 6 years ago

pcarbo commented 6 years ago

I am using rjulia 0.10-1 with R 3.4.1 and Julia 0.6.0 in Linux (Scientific Linux 7). We have found rjulia to be very useful (albeit a bit unstable probably due to substantial changes to Julia).

After installing a package, I discovered that I have to run the using command in Julia before it is accessible in R; e.g.,

Pkg.add("LowRankApprox")
using LowRankApprox

If I don't do this, I get an error something like this:

julia_void_eval("using LowRankApprox")
could not spawn `/software/julia-0.6-el7-x86_64/lib/julia -Cnative -J/software/julia-0.6-el7-x86_64/lib/julia/sys.so --compile=yes --depwarn=yes -O0 --output-ji /home/youngseok/.julia/lib/v0.6/LowRankApprox.ji --output-incremental=yes --startup-file=no --history-file=no --color=no --eval 'while !eof(STDIN)
    eval(Main, deserialize(STDIN))
end
'`: permission denied (EACCES)

This seems to be a Linux-specific bug; I don't get this problem on a Mac.

phaverty commented 6 years ago

Thank you for your report. I will look into it. It sounds like it has something to do with the first load of the package, where the pre-compiling happens. Perhaps, on linux, julia does not want the R process to write to the julia library.

phaverty commented 6 years ago

This replicates on linux for me.

pcarbo commented 6 years ago

@phaverty I still have an error, e.g., on my MacBook Pro:

> j2r("using LowRankApprox;")
could not spawn `/Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia -Ccore2 -J/Applications/Julia-0.6.app/Contents/Resources/julia/lib/julia/sys.dylib --compile=yes --depwarn=yes -O0 --output-ji /Users/pcarbo/.julia/lib/v0.6/LowRankApprox.ji --output-incremental=yes --startup-file=no --history-file=no --color=no --eval 'while !eof(STDIN)
    eval(Main, deserialize(STDIN))
end
'`: permission denied (EACCES)

As before, running using LowRankApprox in Julia resolves the issue.

phaverty commented 6 years ago

Aha! This is related to an issue in julia 6.0: https://github.com/JuliaLang/julia/issues/14577 This is fixed on julia master, but does not appear to have made it to the list for 6.1 The JuliaCall package has addressed this by having a special function for loading julia packages. Their function does a system call to a new julia process that load the package, precompiles and quits. Then they can call "using Package" without error. We could do the same. Hmm.

phaverty commented 6 years ago

I have followed JuliaCall's example and forced precompilation in a second julia process before loading the package in the julia process that is linked to the user's R session.

pcarbo commented 6 years ago

@phaverty I think it works! At least I did not get an error when I did this:

library(rjulia)
jDo("using LowRankApprox")
# Doing 'using LowRankApprox' in a separate thread to force precompilation ...
# NULL
phaverty commented 6 years ago

Great! I've checked that I can subsequently use the loaded package. Sorry that took me a while to figure out.