Non-Contradiction / JuliaCall

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

Error happens when you try to execute command ENV["R_HOME"] #201

Closed Faraz564 closed 1 year ago

Faraz564 commented 1 year ago

I am not able to run Julia in R 4.3 and Julia is 1.9. Julia on PATH but their synatxs are not running. The same error appear after runing syntax i.e. julia_setup(), JuliaCall::julia_command("a= 1+1"). Please find error in detail below Julia version 1.9.1 at location C:\Users\PC\AppData\Local\Programs\JULIA-~1.1\bin will be used. Loading setup script for JuliaCall... Error in .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl", : Error happens when you try to execute command ENV["R_HOME"] = "C:/PROGRA~1/R/R-43~1.1";Base.include(Main,"C:/Users/PC/AppData/Local/R/win-library/4.3/JuliaCall/julia/setup.jl") in Julia. To have more helpful error messages, you could considering running the command in Julia directly

Plz suggest me a solution. JuliaCall

Faraz564 commented 1 year ago

Please someone write a suggestion.

mvnova commented 1 year ago

I have encountered the same problem this week. I've tried downloading different versions of R (4.1, 4.2, 4.3.x) and different versions of Julia (1.9.1, 1.8.5, 1.5.7). I've gone through a number of github issue posts related to this but nothing has worked for me thus far.

Zepeng-Mu commented 1 year ago

I have the same issuse

Faraz564 commented 1 year ago

kindly keep this post updated or write suggestion incase you get out of this issue. I download PowerShell 7 version. While the error is remain the same.

PierreSolomon commented 1 year ago

I have the same problem (windows 11, R 4.2.3, julia 1.9.1). Julia is on path but I get the exact same error message.

michaelmallari commented 1 year ago

Less than a week ago, it was all working for me... R 4.2.3 (updated from 4.1.1) and Julia 1.9.0 (updated from 1.5.4). Even after the update, everything was working fine. However, when I fresh-installed R and Julia (and the necessary packages) on a freshly-formatted/rebuilt MacBook Pro/Ventura (the same one), I got the same errors/issues everyone else is talking about here (even after attempting various versions of R and Julia).

I'm curious... for all the folks experiencing issues also... did things all of a sudden stopped working for you (meaning, it had been working)?

Or is this your first attempt at making JuliaCall work?

FYI... I reformat/rebuild my MacBook Pro ~every 6 months. No issues when I last did this ~6 months ago.

PierreSolomon commented 1 year ago

In my case, it is my first attempt with julia and juliacall.

mvnova commented 1 year ago

It was my first attempt with Julia and JuliaCall, as well.

Zepeng-Mu commented 1 year ago

For me sometimes I run into this problem, but when I restart my rsession, everything is fine. So I really don't know what is the cause of this.

Faraz564 commented 1 year ago

Hi All, Please follow the following procedure it resolve this issue for me.

The PR #199 written by @JackDunnNZ should fix the problem. As a temporary measure, please try

devtools::install_github("https://github.com/JackDunnNZ/JuliaCall/tree/patch-1")

to install the specific version in that PR. The temporary version should be removed cleanly by calling remove.packages("JuliaCall"), and then calling install.packages("JuliaCall") to install the 'main' version when that PR is merged.

njwfish commented 1 year ago

The devtools worked for me!

eddelbuettel commented 1 year ago

Using Ubuntu 23.04 with Julia 1.9.2 from the snap, this still fails for me after installing the patch. Details below.

```r > JuliaCall::julia_eval("2+2") Julia version 1.9.2 at location /snap/julia/83/bin will be used. Loading setup script for JuliaCall... ERROR: LoadError: Failed to precompile CategoricalArrays [324d7699-5711-5eae-9e2f-1d82baa6b597] to "/home/edd/.julia/compiled/v1.9/CategoricalArrays/jl_3HY749". Stacktrace: [1] error(s::String) @ Base ./error.jl:35 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool) @ Base ./loading.jl:2300 [3] compilecache @ ./loading.jl:2167 [inlined] [4] _require(pkg::Base.PkgId, env::String) @ Base ./loading.jl:1805 [5] _require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:1660 [6] macro expansion @ ./loading.jl:1648 [inlined] [7] macro expansion @ ./lock.jl:267 [inlined] [8] require(into::Module, mod::Symbol) @ Base ./loading.jl:1611 [9] include @ ./Base.jl:457 [inlined] [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String) @ Base ./loading.jl:2049 [11] top-level scope @ stdin:3 in expression starting at /home/edd/.julia/packages/RCall/LWzAQ/src/RCall.jl:2 in expression starting at stdin:3 LoadError("/usr/local/lib/R/site-library/JuliaCall/julia/setup.jl", 16, ErrorException("Failed to precompile RCall [6f49c342-dc21-5d91-9882-a32aef131414] to \"/home/edd/.julia/compiled/v1.9/RCall/jl_VVDbM6\".")) Error in .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl", : Error happens when you try to execute command ENV["R_HOME"] = "/usr/lib/R";Base.include(Main,"/usr/local/lib/R/site-library/JuliaCall/julia/setup.jl") in Julia. To have more helpful error messages, you could considering running the command in Julia directly In addition: Warning message: In system2(file.path(.julia$bin_dir, "julia"), shQuote(command), : running command ''/snap/julia/83/bin/julia' '--startup-file=no' '/usr/local/lib/R/site-library/JuliaCall/julia/install_dependency.jl' '/usr/lib/R' 2>&1' had status 139 > Sys.getenv("R_HOME") [1] "/usr/lib/R" > ```

The JuliaConnectoR package works fine.

> library(JuliaConnectoR)
> juliaEval("2+2")
Starting Julia ...
[1] 4
> 
Garzacc97 commented 1 year ago

Faraz I try your code: devtools::install_github("https://github.com/JackDunnNZ/JuliaCall/tree/patch-1") in the Console,

but another error appears to me:

Do you have the same Issue?

Error: Error happens in Julia. UndefVarError: DataFrame not defined Stacktrace: [1] top-level scope @ none:3 [2] eval(m::Module, e::Any) @ Core .\boot.jl:370 [3] top-level scope @ C:\Users\solar7\AppData\Local\R\win-library\4.3\JuliaCall\julia\RmdStd.jl:15 [4] eval @ .\boot.jl:370 [inlined] [5] eval_string(x::String) @ Main.JuliaCall C:\Users\solar7\AppData\Local\R\win-library\4.3\JuliaCall\julia\setup.jl:203 [6] docall(call1::Ptr{Nothing}) @ Main.JuliaCall C:\Users\solar7\AppData\Local\R\win-library\4.3\JuliaCall\julia\setup.jl:176

Non-Contradiction commented 1 year ago

Thank everyone for the feedback. The issue should be fixed by #199 , which is already merged into master. Before the new JuliaCall is on CRAN, you can try the fix by devtools::install_github("Non-Contradiction/JuliaCall"). If the fix does not work, pls feel free to reopen the issue. However, the issue @Garzacc97 have seems to be another one. Hi @Garzacc97 Can you try the code again in a new session? If the issue persists, maybe you can open another issue and we can disuss the problem in the new post instead of this one. Thanks!!!

eddelbuettel commented 1 year ago

Following a fresh github install of JuliaCall and a new session:

> library(JuliaCall)
> julia_setup()
Julia version 1.9.2 at location /snap/julia/83/bin will be used.
Loading setup script for JuliaCall...
ERROR: LoadError: Failed to precompile CategoricalArrays [324d7699-5711-5eae-9e2f-1d82baa6b597] to "/home/edd/.julia/compiled/v1.9/CategoricalArrays/jl_ktNVkA".
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool)
    @ Base ./loading.jl:2300
  [3] compilecache
    @ ./loading.jl:2167 [inlined]
  [4] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1805
  [5] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1660
  [6] macro expansion
    @ ./loading.jl:1648 [inlined]
  [7] macro expansion
    @ ./lock.jl:267 [inlined]
  [8] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1611
  [9] include
    @ ./Base.jl:457 [inlined]
 [10] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
    @ Base ./loading.jl:2049
 [11] top-level scope
    @ stdin:3
in expression starting at /home/edd/.julia/packages/RCall/LWzAQ/src/RCall.jl:2
in expression starting at stdin:3
LoadError("/usr/local/lib/R/site-library/JuliaCall/julia/setup.jl", 16, ErrorException("Failed to precompile RCall [6f49c342-dc21-5d91-9882-a32aef131414] to \"/home/edd/.julia/compiled/v1.9/RCall/jl_rUK5dV\"."))
 Error in .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl",  : 
  Error happens when you try to execute command ENV["R_HOME"] = "/usr/lib/R";Base.include(Main,"/usr/local/lib/R/site-library/JuliaCall/julia/setup.jl") in Julia.
                        To have more helpful error messages,
                        you could considering running the command in Julia directly
In addition: Warning message:
In system2(file.path(.julia$bin_dir, "julia"), shQuote(command),  :
  running command ''/snap/julia/83/bin/julia' '--startup-file=no' '/usr/local/lib/R/site-library/JuliaCall/julia/install_dependency.jl' '/usr/lib/R' 2>&1' had status 139
> 

No change for me it seems.

Non-Contradiction commented 1 year ago

@eddelbuettel It seems that the "installation" step for JuliaCall somehow fails and there is some error on the julia side. How about opening julia directly and run using Pkg; Pkg.build() If the step works, then we may try things on the R side using JuliaCall again.

eddelbuettel commented 1 year ago

Good call. I may well have needed using Pkg; Pkg.build() as Ubuntu's snap system update Julia from 1.9.1 to 1.9.2. So I did that (and it ran for a little moment ending in '59 dependencies successfully precompiled in 119 seconds. 111 already precompiled.'

However, JuliaCall is still sad:

> library(JuliaCall)
> julia_setup()
Julia version 1.9.2 at location /snap/julia/83/bin will be used.
Loading setup script for JuliaCall...
Bus error (core dumped)
edd@rob:$ 
Non-Contradiction commented 1 year ago

@eddelbuettel On the julia side, what is the result of using RCall ? If This is okay, then what is the result of RCall.Rhome ? Is it the same as the position of the R that uses JuliaCall?

eddelbuettel commented 1 year ago

Yeah I removed it earlier. It seems to work. (I only have one R in the path.)

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using RCall       # I have a call to fortunes::fortune() in my .Rprofile

I quit using SAS in 1991 because my productivity jumped at least 20% within one month of using S-Plus.
   -- Frank Harrell
      R-help (November 2003)

julia> 
Non-Contradiction commented 1 year ago

@eddelbuettel Then what is the result of

using RCall
R"library(JuliaCall)"
R"julia_setup()"

in julia?

eddelbuettel commented 1 year ago

Looks promising:

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using RCall

I recently attended a Ph.D. prelim exam where the candidate had proposed research on various ways of defining an R^2 statistic in the original data scale from a linear model fit to data in a
transformed scale determined by the Box-Cox method. There were seven different possible definitions for R^2, all of which, as acknowledged by the candidate and by the thesis advisor, were incorrect.
The purpose of this path-breaking study is to determine in some way which of these seven possible incorrect definitions should be used. My suggestion that the obvious answer was "none of them" was
regarded as somewhat heretical.
   -- Douglas Bates
      R-help (August 2000)

julia> R"library(JuliaCall)"
RObject{StrSxp}
[1] "JuliaCall" "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"   "base"     

julia> R"julia_setup()"
Julia version 1.9.2 at location /snap/julia/83/bin will be used.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
RObject{EnvSxp}
<environment: 0x4b59958>

julia> 

Should I try without my ~/.Rprofile ? Come to think about it I have colorout (great but not-on-CRAN package to prettify console) there and that may throw a spanner.

eddelbuettel commented 1 year ago

Not that is not it. I also get Bus error (core dumped) if I start R --vanilla.

Non-Contradiction commented 1 year ago

The fact that JuliaCall is okay in julia through RCall but is not okay from R means that the problem is really subtle. To simplify things a little bit, what is the result of running library(JuliaCall); julia_setup() non-interactively, for example, by RScript?

eddelbuettel commented 1 year ago

Still bad:

edd@rob:~$ Rscript -e 'library(JuliaCall); julia_setup()'
Julia version 1.9.2 at location /snap/julia/83/bin will be used.
Loading setup script for JuliaCall...
Bus error (core dumped)
edd@rob:~$ 
Non-Contradiction commented 1 year ago

These are the main steps in julia_setup() which should be relevant to the error:

JULIA_HOME <- JuliaCall:::julia_locate()

dll_command <- system.file("julia/libjulia.jl", package = "JuliaCall")
dll_file <- system2(file.path(JULIA_HOME, "julia"), shQuote(dll_command),
                    stdout = TRUE)

try(dyn.load(dll_file))

JuliaCall:::juliacall_initialize(dll_file, JULIA_HOME, "")

Rhomeset <- paste0('ENV["R_HOME"] = "', R.home(), '";')
JuliaCall:::juliacall_cmd(Rhomeset)
message(1)

JuliaCall:::juliacall_cmd("Base.load_julia_startup();")
message(2)

JuliaCall:::juliacall_cmd("using RCall")
message(3)

JuliaCall:::juliacall_cmd("unsafe_store!(cglobal((:R_CStackLimit,RCall.libR),Csize_t), typemax(Csize_t))")
message(4)

What are the results of the code chunk?

eddelbuettel commented 1 year ago

Weird. Pasting then one-by-one into a fresh session just ... works!. I really appreciate your patience.

```r $ R R version 4.3.1 (2023-06-16) -- "Beagle Scouts" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. Just now I had an apparently insurmountable problem that's been bugging me for days, but phrasing my question in a form suitable for the R-help list enabled me to solve my own problem in two minutes flat. Thanks everyone. -- Robin Hankin R-help (March 2005) > JULIA_HOME <- JuliaCall:::julia_locate() > dll_command <- system.file("julia/libjulia.jl", package = "JuliaCall") > dll_file <- system2(file.path(JULIA_HOME, "julia"), shQuote(dll_command), stdout = TRUE) > try(dyn.load(dll_file)) > JuliaCall:::juliacall_initialize(dll_file, JULIA_HOME, "") [1] TRUE > Rhomeset <- paste0('ENV["R_HOME"] = "', R.home(), '";') > JuliaCall:::juliacall_cmd(Rhomeset) [1] TRUE > message(1) 1 > JuliaCall:::juliacall_cmd("Base.load_julia_startup();") [1] TRUE > message(2) 2 > JuliaCall:::juliacall_cmd("using RCall") [1] TRUE > message(3) 3 > JuliaCall:::juliacall_cmd("unsafe_store!(cglobal((:R_CStackLimit,RCall.libR),Csize_t), typemax(Csize_t))") [1] TRUE > message(4) 4 > > search() [1] ".GlobalEnv" "package:stats" "package:graphics" "package:grDevices" "package:utils" "package:datasets" "package:methods" "Autoloads" "package:base" > ls() [1] "dll_command" "dll_file" "JULIA_HOME" "Rhomeset" > ```
Non-Contradiction commented 1 year ago

...Then I guess that the issue may be some other julia packages... Maybe we can try more code to see where the problem is from... Also thank you for your patience and the feedback. Continuing with the previous code chunk,


## JuliaCall:::juliacall_cmd("Base.load_julia_startup()")
JuliaCall:::juliacall_cmd("using Pkg")
message(5)
## needed by console
JuliaCall:::juliacall_cmd("const STDIN = stdin")
message(6)
## needed by rmarkdown stdout capture
JuliaCall:::juliacall_cmd("const STDOUT = stdout")
message(7)
## needed by functions like det
JuliaCall:::juliacall_cmd("using LinearAlgebra")
message(8)
## needed by functions like mean
JuliaCall:::juliacall_cmd("using Statistics")
message(9)

JuliaCall:::juliacall_cmd('const julia07 = VERSION > v"0.6.5"')
JuliaCall:::juliacall_cmd('const julia14 = VERSION > v"1.3.2"')
message(10)

## needed by eval_string function
JuliaCall:::juliacall_cmd("const parse = Meta.parse")
message(11)
## needed by system checking
JuliaCall:::juliacall_cmd("const is_windows = Sys.iswindows")
message(12)
## needed by display system
JuliaCall:::juliacall_cmd("const Display = AbstractDisplay")
message(13)
JuliaCall:::juliacall_cmd("const readstring(s) = read(s, String)")
message(14)
## needed by console
JuliaCall:::juliacall_cmd("using REPL")
message(15)
JuliaCall:::juliacall_cmd("const REPLCompletions = REPL.REPLCompletions")
message(16)

## needed by IRjulia display
JuliaCall:::juliacall_cmd("using Base64")
message(17)

JuliaCall:::juliacall_cmd("using Suppressor")
message(18)

## Fix https://github.com/JuliaInterop/RCall.jl/issues/289
## unsafe_store!(cglobal((:R_CStackLimit,RCall.libR),Csize_t), typemax(Csize_t))

JuliaCall:::juliacall_cmd("const need_display = length(Base.Multimedia.displays) < 2")
message(19)

JuliaCall:::juliacall_cmd("import Base.Multimedia.display")
message(20)
eddelbuettel commented 1 year ago

It's "using Pkg" that does me in:

>  JULIA_HOME <- JuliaCall:::julia_locate()
> dll_command <- system.file("julia/libjulia.jl", package = "JuliaCall")
> dll_file <- system2(file.path(JULIA_HOME, "julia"), shQuote(dll_command),  stdout = TRUE)
> try(dyn.load(dll_file))
> JuliaCall:::juliacall_initialize(dll_file, JULIA_HOME, "")
[1] TRUE
> Rhomeset <- paste0('ENV["R_HOME"] = "', R.home(), '";')
> JuliaCall:::juliacall_cmd(Rhomeset)
[1] TRUE                  
> JuliaCall:::juliacall_cmd("Base.load_julia_startup();")
[1] TRUE                        
> JuliaCall:::juliacall_cmd("using RCall")
[1] TRUE
>  JuliaCall:::juliacall_cmd("unsafe_store!(cglobal((:R_CStackLimit,RCall.libR),Csize_t), typemax(Csize_t))")
[1] TRUE
> JuliaCall:::juliacall_cmd("Base.load_julia_startup()")
[1] TRUE
> JuliaCall:::juliacall_cmd("using Pkg")
Bus error (core dumped)
$

Any idea ?

santoshbs commented 1 year ago

I get the same error even after installing the github version:

Julia version 1.9.3 at location /home/xxx/packages/julias/julia-1.9/bin will be used.

Loading setup script for JuliaCall...

Warning message in system2(file.path(.julia$bin_dir, "julia"), shQuote(command), :
“running command ''/home/xxx/packages/julias/julia-1.9/bin/julia' '--startup-file=no' '/home/xxx/R/x86_64-pc-linux-gnu-library/4.3/JuliaCall/julia/install_dependency.jl' '/usr/lib/R' 2>&1' had status 139”

Error in .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl", : Error happens when you try to execute command ENV["R_HOME"] = "/usr/lib/R";Base.include(Main,"/home/xxx/R/x86_64-pc-linux-gnu-library/4.3/JuliaCall/julia/setup.jl") in Julia.
                        To have more helpful error messages,
                        you could considering running the command in Julia directly
Traceback:

1. julia_setup()
2. .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl", 
 .     package = "JuliaCall"), "\")"))
3. stop(paste0("Error happens when you try to execute command ", 
 .     cmd, " in Julia.\n                        To have more helpful error messages,\n                        you could considering running the command in Julia directly"))
cdriveraus commented 1 month ago

This was a rocky start to my test of whether using Julia as a computational backend would be robust for general R package users... JuliaCall will not be maintained on CRAN it seems?

R version 4.4.0, Windows 11.

> library(diffeqr)
Warning message:
package ‘diffeqr’ was built under R version 4.4.1 
> diffeq_setup()
Julia version 1.8.5 at location C:\Users\Driver\AppData\Roaming\R\data\R\JULIAC~1\julia\18B0F0~1.5\JULIA-~1.5\bin will be used.
Loading setup script for JuliaCall...
Error in .julia$cmd(paste0(Rhomeset, "Base.include(Main,\"", system.file("julia/setup.jl",  : 
  Error happens when you try to execute command ENV["R_HOME"] = "C:/PROGRA~1/R/R-44~1.0";Base.include(Main,"C:/Users/Driver/AppData/Local/R/win-library/4.4/JuliaCall/julia/setup.jl") in Julia.
                        To have more helpful error messages,
                        you could considering running the command in Julia directly