How to set JULIA_PROJECT for JuliaCall?

I need access to a pre-existing project environment within JuliaCall.

The following MWE does not work:

MWE:

Create the ‘pre-existing’ environment

# run this in the terminal
$ cd ~/
$ mkdir /tmp/testenv && cd /tmp/testenv
$ julia
julia> using Pkg; Pkg.activate("/tmp/testenv")
julia> Pkg.add(DataFrames)

Accessing it in R [testjuliacall.R]

# testjuliacall.R
library(JuliaCall)
Sys.setenv(JULIA_PROJECT="/tmp/testenv")
julia_library("DataFrames")

Problem

Running testjuliacall.R produces the following error:

Julia version 1.6.0 at location /usr/local/julia-1.6.0/bin will be used.
Loading setup script for JuliaCall...
Finish loading setup script for JuliaCall.
Error: Error happens in Julia.
ArgumentError: Package DataFrames not found in current path:
- Run `import Pkg; Pkg.add("DataFrames")` to install the DataFrames package.

Stacktrace:
[1] require(into::Module, mod::Symbol)
@ Base ./loading.jl:871
[2] eval
@ ./boot.jl:360 [inlined]
[3] eval_string(x::String)
@ Main.JuliaCall ~/R/x86_64-pc-linux-gnu-library/4.0/JuliaCall/julia/setup.jl:195
[4] docall(call1::Ptr{Nothing})
@ Main.JuliaCall ~/R/x86_64-pc-linux-gnu-library/4.0/JuliaCall/julia/setup.jl:168

1 Like

I believe this should work, and I just verify that it works on Windows 10.
And I notice that the environment is created at "/tmp/testenv"
but in the JuliaCall script, the path is "/tmp/testproj". Is this a typo, or is it the actual code?
One quick thing to check is that JuliaCall has some julia package dependencies like RCall, which should be installed into the environment at "/tmp/testproj" if JuliaCall “correctly” picks that environment, otherwise JuliaCall won’t be able to finish loading the setup script.

Thanks, @Non-Contradiction. I’ll fix that typo in the post. It turns out the actual code on which the MWE was based also had another issue involving the package (not DataFrames) being loaded!