Non-Contradiction / JuliaCall

Embed Julia in R
https://non-contradiction.github.io/JuliaCall/index.html
Other
267 stars 36 forks source link

setup script works in Julia but failed in R #78

Closed jason-xuan closed 5 years ago

jason-xuan commented 5 years ago

I installed the package and tried to run the julia_setup() function, but it failed, showed me the command and suggested me to run it in the Julia REPL. I rebuilt the package and run the command, it worked. But when I switched back to R, it failed again. I don't understand what purpose the setup function is. Is there any workaround?

C:\Users\zjxua\Desktop                                                                                                                       
λ  R.exe                                                                                                                                     

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"                                                                                             
Copyright (C) 2018 The R Foundation for Statistical Computing                                                                                
Platform: x86_64-w64-mingw32/x64 (64-bit)                                                                                                    

R                                                                                                                                            

'license()''licence()'                                                                                                                       

R.                                                                                                                                           
'contributors()'                                                                                                                             
'citation()'RR                                                                                                                               

'demo()''help()'                                                                                                                             
'help.start()'HTML                                                                                                                           
'q()'R.                                                                                                                                      

> library(JuliaCall)                                                                                                                         
> j <- julia_setup()                                                                                                                         
Julia version 1.0.3 at location C:\Users\zjxua\AppData\Local\JULIA-~1.3\bin will be used.                                                    
Loading setup script for JuliaCall...                                                                                                        
ERROR: LoadError: RCall not properly installed. Please run Pkg.build("RCall")                                                                
Stacktrace:                                                                                                                                  
 [1] error(::String) at .\error.jl:33                                                                                                        
 [2] top-level scope at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:34                                                           
 [3] include at .\boot.jl:317 [inlined]                                                                                                      
 [4] include_relative(::Module, ::String) at .\loading.jl:1044                                                                               
 [5] include(::Module, ::String) at .\sysimg.jl:29                                                                                           
 [6] top-level scope at none:2                                                                                                               
 [7] eval at .\boot.jl:319 [inlined]                                                                                                         
 [8] eval(::Expr) at .\client.jl:393                                                                                                         
 [9] top-level scope at .\none:3                                                                                                             
in expression starting at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:31                                                         
LoadError("C:\\Users\\zjxua\\Documents\\R\\win-library\\3.5\\JuliaCall\\julia\\setup.jl", 72, ErrorException("Failed to precompile RCall [6f4
9c342-dc21-5d91-9882-a32aef131414] to C:\\Users\\zjxua\\.julia\\compiled\\v1.0\\RCall\\8GFyb.ji.")) Error in .julia$cmd(paste0("Base.include(
Main,\"", system.file("julia/setup.jl",  :                                                                                                   
  Error happens when you try to execute command Base.include(Main,"C:/Users/zjxua/Documents/R/win-library/3.5/JuliaCall/julia/setup.jl") in J
ulia.                                                                                                                                        
                        To have more helpful error messages,                                                                                 
                        you could considering running the command in Julia directly                                                          
Warning message:                                                                                                                         
In system2(file.path(.julia$bin_dir, "julia"), shQuote(command),  :                                                                          
  status code of command '"C:\Users\zjxua\AppData\Local\JULIA-~1.3\bin/julia" "C:/Users/zjxua/Documents/R/win-library/3.5/JuliaCall/julia/install_dependency    
.jl" "C:/PROGRA~1/R/R-35~1.2"' is 1                                                                                                          
> q()                                                                                                                                                                                                                                                           
Julia exit.                                                                                                                                  
C:\Users\zjxua\Desktop                                                                                                                       
λ  julia                                                                                                                                     
               _                                                                                                                             
   _       _ _(_)_     |  Documentation: https://docs.julialang.org                                                                          
  (_)     | (_) (_)    |                                                                                                                     
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.                                                                              
  | | | | | | |/ _` |  |                                                                                                                     
  | | |_| | | | (_| |  |  Version 1.0.3 (2018-12-18)                                                                                         
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release                                                                            
|__/                   |                                                                                                                     

julia> using Pkg                                                                                                                             

julia> Pkg.build("RCall")                                                                                                                    
  Building CodecZlib → `C:\Users\zjxua\.julia\packages\CodecZlib\DAjXH\deps\build.log`                                                       
  Building Conda ────→ `C:\Users\zjxua\.julia\packages\Conda\uQitS\deps\build.log`                                                           
  Building RCall ────→ `C:\Users\zjxua\.julia\packages\RCall\RPlFw\deps\build.log`                                                           

julia> Base.include(Main,"C:/Users/zjxua/Documents/R/win-library/3.5/JuliaCall/julia/setup.jl")                                              
[ Info: Precompiling RCall [6f49c342-dc21-5d91-9882-a32aef131414]                                                                            
Main.JuliaCall                                                                                                                               

julia> exit()                                                                                                                                
C:\Users\zjxua\Desktop                                                                                                                       
λ  R.exe                                                                                                                                     

R version 3.5.2 (2018-12-20) -- "Eggshell Igloo"                                                                                             
Copyright (C) 2018 The R Foundation for Statistical Computing                                                                                
Platform: x86_64-w64-mingw32/x64 (64-bit)                                                                                                    

R                                                                                                                                            

'license()''licence()'                                                                                                                       

R.                                                                                                                                           
'contributors()'                                                                                                                             
'citation()'RR                                                                                                                               

'demo()''help()'                                                                                                                             
'help.start()'HTML                                                                                                                           
'q()'R.                                                                                                                                      

> library(JuliaCall)                                                                                                                         
> j <- julia_setup()                                                                                                                         
Julia version 1.0.3 at location C:\Users\zjxua\AppData\Local\JULIA-~1.3\bin will be used.                                                    
Loading setup script for JuliaCall...                                                                                                        
ERROR: LoadError: RCall not properly installed. Please run Pkg.build("RCall")                                                                
Stacktrace:                                                                                                                                  
 [1] error(::String) at .\error.jl:33                                                                                                        
 [2] top-level scope at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:34                                                           
 [3] include at .\boot.jl:317 [inlined]                                                                                                      
 [4] include_relative(::Module, ::String) at .\loading.jl:1044                                                                               
 [5] include(::Module, ::String) at .\sysimg.jl:29                                                                                           
 [6] top-level scope at none:2                                                                                                               
 [7] eval at .\boot.jl:319 [inlined]                                                                                                         
 [8] eval(::Expr) at .\client.jl:393                                                                                                         
 [9] top-level scope at .\none:3                                                                                                             
in expression starting at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:31                                                         
LoadError("C:\\Users\\zjxua\\Documents\\R\\win-library\\3.5\\JuliaCall\\julia\\setup.jl", 72, ErrorException("Failed to precompile RCall [6f4
9c342-dc21-5d91-9882-a32aef131414] to C:\\Users\\zjxua\\.julia\\compiled\\v1.0\\RCall\\8GFyb.ji.")) Error in .julia$cmd(paste0("Base.include(
Main,\"", system.file("julia/setup.jl",  :                                                                                                   
  Error happens when you try to execute command Base.include(Main,"C:/Users/zjxua/Documents/R/win-library/3.5/JuliaCall/julia/setup.jl") in J
ulia.                                                                                                                                        
                        To have more helpful error messages,                                                                                 
                        you could considering running the command in Julia directly                                                          
>                                                                                                                                            
Non-Contradiction commented 5 years ago

Thank you for the feedback. What is the result of using RCall in Julia?

jason-xuan commented 5 years ago

It works, but at first I need to rebuild it, it seems that the j <- julia_setup() function damages the RCall package

julia> using RCall
[ Info: Precompiling RCall [6f49c342-dc21-5d91-9882-a32aef131414]
ERROR: LoadError: RCall not properly installed. Please run Pkg.build("RCall")
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] top-level scope at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:34
 [3] include at .\boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at .\loading.jl:1044
 [5] include(::Module, ::String) at .\sysimg.jl:29
 [6] top-level scope at none:2
 [7] eval at .\boot.jl:319 [inlined]
 [8] eval(::Expr) at .\client.jl:393
 [9] top-level scope at .\none:3
in expression starting at C:\Users\zjxua\.julia\packages\RCall\RPlFw\src\RCall.jl:31
ERROR: Failed to precompile RCall [6f49c342-dc21-5d91-9882-a32aef131414] to C:\Users\zjxua\.julia\compiled\v1.0\RCall\8GFyb.ji.
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at .\loading.jl:1203
 [3] _require(::Base.PkgId) at .\loading.jl:960
 [4] require(::Base.PkgId) at .\loading.jl:858
 [5] require(::Module, ::Symbol) at .\loading.jl:853

julia> using Pkg

julia> Pkg.build("RCall")
  Building CodecZlib → `C:\Users\zjxua\.julia\packages\CodecZlib\DAjXH\deps\build.log`
  Building Conda ────→ `C:\Users\zjxua\.julia\packages\Conda\uQitS\deps\build.log`
  Building RCall ────→ `C:\Users\zjxua\.julia\packages\RCall\RPlFw\deps\build.log`

julia> using RCall
[ Info: Precompiling RCall [6f49c342-dc21-5d91-9882-a32aef131414]

julia> z = 1
1

julia> @rput z
1

R> z
[1] 1

R> rnorm(10)
 [1] -1.5466842 -1.0761188  1.0797469  0.2911725 -2.1343276 -0.1167468
 [7]  2.1759966 -0.7001125  2.2242575  0.8921539

julia> R"rnorm(10)"
RObject{RealSxp}
 [1]  0.29118249  0.44693269  1.02731955 -0.83262039 -0.41408416  1.00665726
 [7]  0.60336981 -0.01557677  1.02081239 -0.96174732

julia>
Non-Contradiction commented 5 years ago

That seems interesting... What is the result of RCall.Rhome? If the result matches R.home() in R, then it seems that julia_setup() should also work.

jason-xuan commented 5 years ago

Actually, they are the same... They are supposed to work but actually don't.

Non-Contradiction commented 5 years ago

Are they exactly the same? For example, if RCall.Rhome and R.home() are in Windows short form and full form, they represent the same file but are not exactly the same, then JuliaCall will try to build the RCall again, which somehow break the RCall installation...

jason-xuan commented 5 years ago

Well... I don't know if this is what you mean, but yes, the "string" is not exactly the same but indicating the same address. But it's not the short form and full form, but about Backslash.

julia> RCall.Rhome
"C:\\PROGRA~1\\R\\R-35~1.2"
> R.home()
[1] "C:/PROGRA~1/R/R-35~1.2"
Non-Contradiction commented 5 years ago

I'm still thinking about why the error happens. But one thing to try is to use julia_setup(install = FALSE) to skip the installation of RCall.jl and Suppressor.jl by JuliaCall. This should work fine with RCall and Suppressor already installed and set up correctly, and by install = FALSE, JuliaCall will just use the packages already installed and won't mess up with them.

jason-xuan commented 5 years ago

thanks! julia_setup(install = FALSE) works for me.

VEZY commented 5 years ago

Sorry to re-open this issue, but I have the same issue, and unfortunately julia_setup(install = FALSE) didn't work for me. I have Julia 1.1.1, and R 3.6.1. When I call julia <- julia_setup(install = FALSE), it returns an error (same as with julia_setup(install = FALSE)):

Julia version 1.1.1 at location C:\Users\vezy\AppData\Local\JuliaPro-1.1.1.1\Julia-1.1.1\bin will be used.
Loading setup script for JuliaCall...
Error in .julia$cmd(paste0("Base.include(Main,\"", system.file("julia/setup.jl",  : 
  Error happens when you try to execute command Base.include(Main,"D:/Mes Donnees/R/win-library/3.6/JuliaCall/julia/setup.jl") in Julia.
                        To have more helpful error messages,
                        you could considering running the command in Julia directly

I installed manually RCall and Suppressor in julia, and both installations worked. I also tested RCall and it works perfectly. If I include setup.jl from Julia, it works, i.e.:

Base.include(Main,"D:/Mes Donnees/R/win-library/3.6/JuliaCall/julia/setup.jl")

I'm on windows too, and the path to the r home is similar (different format though):

julia> RCall.Rhome
"C:\\Program Files\\R\\R-3.6.1"
R> R.home()
[1] "C:/Program Files/R/R-3.6.1"

Any suggestions ?

Non-Contradiction commented 5 years ago

It is a little strange to have RCall and Suppressor work perfectly and setup.jl also works in Julia but the same loading script fails in JuliaCall. But JuliaPro is not tested thoroughly, so the problem may be with JuliaPro? Is it convenient for you to check if the same problem can be reproduced on ordinary Julia? I will also try to test JuliaPro probably within two or three days.

VEZY commented 5 years ago

Installing the package directly from julia worked ! And actually I was using VS Code, but the path to Julia is the one from JuliaPro-1.1.1.1 because I installed JuliaPro before, so I linked VS Code to this installation to avoid having several Julia exe.

Thank you very much !

Non-Contradiction commented 5 years ago

Thanks for the feedback! I just added a commit which deals with "\" and "/" in paths. So this kind of problem should be solved.