RCall.jl icon indicating copy to clipboard operation
RCall.jl copied to clipboard

Rcall installation

Open nanjalaruth opened this issue 5 years ago • 25 comments

ERROR: LoadError: R cannot be found. Set the "R_HOME" environment variable to re-run Pkg.build("RCall").

nanjalaruth avatar Feb 14 '20 12:02 nanjalaruth

Try setting the environment variable first before installing, for example:

ENV["R_HOME"] = "C:\\Program Files\\R\\R-3.6.2"

hsm207 avatar Feb 29 '20 12:02 hsm207

I potentially have the same issue:

Windows 10, Julia 1.4, trying to install RCall with Julia's Conda-R-version.

Pkg.add("RCall")
Pkg.build("RCall")

yields:

   Building Conda → `C:\Users\joach\.julia\packages\Conda\3rPhK\deps\build.log`
   Building RCall → `C:\Users\joach\.julia\packages\RCall\g7dhB\deps\build.log`
┌ Error: Error building `RCall`:
│ ERROR: LoadError: R cannot be found. Set the "R_HOME" environment variable to re-run Pkg.build("RCall").
│ Stacktrace:
│  [1] error(::String) at .\error.jl:33
│  [2] top-level scope at C:\Users\joach\.julia\packages\RCall\g7dhB\deps\build.jl:49
│  [3] include(::String) at .\client.jl:439
│  [4] top-level scope at none:5
│ in expression starting at C:\Users\joach\.julia\packages\RCall\g7dhB\deps\build.jl:10
└ @ Pkg.Operations D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Pkg\src\Operations.jl:892

Any suggestions?

drhouse82 avatar Mar 29 '20 20:03 drhouse82

In R, run R.home() to figure out the correct value for R_HOME.

Then, in julia, set the R_HOME environment variable first before making the Pkg calls.

Does this work?

hsm207 avatar Mar 31 '20 12:03 hsm207

I do not have a standalone R installation. Hence, I cannot check the folder. My understanding was, that RCall.jl would take care of installation R via Conda if and R_HOME could be left empty. Is this incorrect?

drhouse82 avatar Mar 31 '20 12:03 drhouse82

I think you are right according to the documentation.

I used Julia from dockerhub and ran:

using Pkg
Pkg.add("RCall")

I got an error too but it's different from yours:

Building Conda → `~/.julia/packages/Conda/3rPhK/deps/build.log`
 Building RCall → `~/.julia/packages/RCall/g7dhB/deps/build.log`
┌ Error: Error building `RCall`:
│ ERROR: LoadError: R_HOME is not a directory.
│ Stacktrace:
│  [1] error(::String) at ./error.jl:33
│  [2] top-level scope at /root/.julia/packages/RCall/g7dhB/deps/build.jl:44
│  [3] include(::String) at ./client.jl:439
│  [4] top-level scope at none:5
│ in expression starting at /root/.julia/packages/RCall/g7dhB/deps/build.jl:10
└ @ Pkg.Operations /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Pkg/src/Operations.jl:892

I guess the "auto install R" feature is broken.

hsm207 avatar Mar 31 '20 13:03 hsm207

Guys I had the same issue last night. Clearly many people have the same issue.

@simonbyrne @randy3k Can the README be updated w/ better RCall installation instructions?

  1. In R, run R.home() to find the correct directory
> R.home()
[1] "/Library/Frameworks/R.framework/Resources"
  1. In Julia
ENV["R_HOME"] = "/Library/Frameworks/R.framework/Resources"
  1. build, add etc...

azev77 avatar Apr 23 '20 12:04 azev77

Alternatively, is there maybe a rather straightforward way to install R through Conda.jl? This would probably be also useful in the readme. I myself, however, couldn't figure out an easy way, unfortunately. (But I have zero R experience...)

drhouse82 avatar Jun 14 '20 11:06 drhouse82

@drhouse82

To install R through Conda.jl try:

using Conda
Conda.add("r", channel="r")

This will install r in the base environment using the conda installed by Conda.jl. To verify everything works:

source  ~/.julia/conda/3/bin/activate base
R

Once I installed R this way, I was able to install and use RCall without having to define the R_HOME environment variable. Just add RCall in the Pkg REPL and using RCall in the Julia REPL.

This is the version of Julia I am using:

Julia Version 1.4.2
Commit 44fa15b150* (2020-05-23 18:35 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_GPG = 3673DF529D9049477F76B37566E3C7DC03D6E495
  JULIA_VERSION = 1.4.2
  JULIA_PATH = /usr/local/julia

hsm207 avatar Jun 16 '20 13:06 hsm207

@hsm207

Thank you for your guidance. Unfortunately, it didnt go so smooth for me.

Adding R through conda worked out nicely.

For me (windows 10), activation of the environment is at ~/.julia/conda/3/Scripts/activate base

Then, adding / building RCall says ENV["R_HOME"] is not properly defined. I add ENV["R_HOME"] = "C:\\Users\\<username>\\.julia\\conda\\3\\Lib\\R"

Then, building R says

┌ Error: Error building `RCall`:
│ ERROR: could not load library "C:\Users\joach\.julia\conda\3\Lib\R\bin\x64\R.dll"
│ The specified module could not be found.
│ ERROR: LoadError: Try adding C:\Users\joach\.julia\conda\3\Lib\R\bin\x64 to the "PATH" environmental variable and restarting Julia.
│ Stacktrace:
│  [1] error(::String) at .\error.jl:33
│  [2] validate_libR(::String) at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\setup.jl:24
│  [3] locate_libR(::String) at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\setup.jl:43
│  [4] top-level scope at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\build.jl:53
│  [5] include(::String) at .\client.jl:439
│  [6] top-level scope at none:5
│ in expression starting at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\build.jl:11
│ caused by [exception 1]
│ could not load library "C:\Users\joach\.julia\conda\3\Lib\R\bin\x64\R.dll"
│ The specified module could not be found.
│ Stacktrace:
│  [1] dlopen(::String, ::UInt32; throw_error::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Libdl\src\Libdl.jl:109
│  [2] dlopen at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Libdl\src\Libdl.jl:109 [inlined] (repeats 2 times)
│  [3] validate_libR(::String) at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\setup.jl:16
│  [4] locate_libR(::String) at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\setup.jl:43
│  [5] top-level scope at C:\Users\joach\.julia\packages\RCall\jOnwc\deps\build.jl:53
│  [6] include(::String) at .\client.jl:439
│  [7] top-level scope at none:5
└ @ Pkg.Operations D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Pkg\src\Operations.jl:892

Adding the path entry and restarting julia doesnt change the error message. The file C:\Users\joach.julia\conda\3\Lib\R\bin\x64\R.dll does exist... So I don't know how to proceed here...

drhouse82 avatar Jun 18 '20 07:06 drhouse82

@drhouse82

Can you share the output of versioninfo() from your Julia REPL?

Once you installed R via conda.jl, can you actually run R? e.g. from cmd, run the relevant binary

hsm207 avatar Jun 18 '20 09:06 hsm207

@hsm207 I can use R, yes.

versioninfo output is:

Julia` Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_EDITOR = "C:\Users\joach\AppData\Local\Programs\Microsoft VS Code\Code.exe"
  JULIA_NUM_THREADS = 8

drhouse82 avatar Jun 18 '20 12:06 drhouse82

@drhouse82

After you add the path to PATH and restart Julia, does the path to R.dll appear in ENV["PATH"]?

hsm207 avatar Jun 18 '20 14:06 hsm207

Yes.

julia> occursin(";C:\\Users\\joach\\.julia\\conda\\3\\Lib\\R\\bin\\x64;", ENV["PATH"])
true

drhouse82 avatar Jun 19 '20 06:06 drhouse82

Content of that folder:

04/11/2020  02:31 PM    <DIR>          .
04/11/2020  02:31 PM    <DIR>          ..
10/03/2019  08:17 PM            19,968 open.exe
10/03/2019  08:17 PM        30,573,056 R.dll
10/03/2019  08:17 PM           106,496 R.exe
10/03/2019  08:17 PM           127,989 Rblas.dll
10/03/2019  08:17 PM           105,984 Rcmd.exe
10/03/2019  08:17 PM            90,112 Rfe.exe
10/03/2019  08:17 PM           401,458 Rgraphapp.dll
10/03/2019  08:17 PM            90,112 Rgui.exe
10/03/2019  08:17 PM           132,002 Riconv.dll
10/03/2019  08:17 PM         2,497,536 Rlapack.dll
10/03/2019  08:17 PM            94,208 Rscript.exe
10/03/2019  08:17 PM            91,136 RSetReg.exe
10/03/2019  08:17 PM            90,624 Rterm.exe

Interestignly, I cannot start R.exe from commandline from that folder, without previously activating the base environment. Otherwise I get a popup: Title: Rterm.ext - System error Message: The code execution cannot proceed because liblmza-5.dll was not found. Reinstalling the program may fix this problem.

R version info

R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

drhouse82 avatar Jun 19 '20 06:06 drhouse82

Interestignly, I cannot start R.exe from commandline from that folder, without previously activating the base environment.

This is as expected because when you activate a conda environment, it modifies some environment variables to make the R.exe it installed discoverable.

I'm out of ideas. I would recommend working inside a docker container built from the official julia image.

hsm207 avatar Jun 19 '20 07:06 hsm207

Windows installation is always tricker. Try putting the path C:\Users\joach\.julia\conda\3\Lib\R\bin\x64\ to your PATH variable.

randy3k avatar Jun 19 '20 07:06 randy3k

@drhouse82 You can’t just put it in the PATH variable in Julia. You’ll need to put it in before you run Julia. Like this https://www.architectryan.com/2018/08/31/how-to-change-environment-variables-on-windows-10/

randy3k avatar Jun 19 '20 07:06 randy3k

Could you also try activating the conda environment and then launching Julia?

randy3k avatar Jun 19 '20 07:06 randy3k

Windows installation is always tricker. Try putting the path C:\Users\joach\.julia\conda\3\Lib\R\bin\x64\ to your PATH variable.

This is the same path I was talking about before, right? or do I miss something?

drhouse82 avatar Jun 19 '20 10:06 drhouse82

@drhouse82 You can’t just put it in the PATH variable in Julia. You’ll need to put it in before you run Julia. Like this https://www.architectryan.com/2018/08/31/how-to-change-environment-variables-on-windows-10/

Yes, this is what I did.

drhouse82 avatar Jun 19 '20 10:06 drhouse82

Could you also try activating the conda environment and then launching Julia?

This works indeed. Thanks for your help.

drhouse82 avatar Jun 19 '20 10:06 drhouse82

Hi all,

I am having a similar issue. I can also make a separate post if necessary.

Basically I am trying to install Rcall and getting the error:

julia> R_HOME="/usr/lib/R"
"/usr/lib/R"

(@v1.4) pkg> add Rcall
ERROR: The following package names could not be resolved:
 * Rcall (not found in project, manifest or registry)

My R is working and runnable. I am running Ubuntu on Windows 10 which may be the issue. I have tried the steps above with no avail. The only issue is I am not sure if I activated conda correctly as was suggested above. I simply made a new conda environment and activated it and then ran Julia.

Any help would be appreciated! Apologies if this belongs in a new post I can move it over if needed.

samd1993 avatar Jul 01 '20 00:07 samd1993

It is RCall, not Rcall.

randy3k avatar Jul 01 '20 00:07 randy3k

Please forget I exist.....

samd1993 avatar Jul 01 '20 00:07 samd1993

Wait maybe I am not that crazy. So now when I run this analysis I've been trying to run I get the same error about RCall not being properly compiled. Below is the output:

samd1993@DESKTOP-V6PBDGC:~/mimix$ julia scripts/sim-mcmc.jl \
>     --data simulation-study/configs/data.yml \
>     --hyper simulation-study/configs/hyper.yml \
>     --monitor simulation-study/configs/monitor.yml \
>     --inits simulation-study/configs/inits.yml \
>     --seed 123 \
>     --factors 20 \
>     simulation-results
ERROR: LoadError: RCall not properly installed. Please run Pkg.build("RCall")
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] top-level scope at /home/samd1993/.julia/packages/RCall/Qzssx/src/RCall.jl:36
 [3] include(::Module, ::String) at ./Base.jl:377
 [4] top-level scope at none:2
 [5] eval at ./boot.jl:331 [inlined]
 [6] eval(::Expr) at ./client.jl:449
 [7] top-level scope at ./none:3
in expression starting at /home/samd1993/.julia/packages/RCall/Qzssx/src/RCall.jl:33
ERROR: LoadError: Failed to precompile RCall [6f49c342-dc21-5d91-9882-a32aef131414] to /home/samd1993/.julia/compiled/v1.4/RCall/8GFyb_iiRov.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1272
 [3] _require(::Base.PkgId) at ./loading.jl:1029
 [4] require(::Base.PkgId) at ./loading.jl:927
 [5] require(::Module, ::Symbol) at ./loading.jl:922
 [6] include(::Module, ::String) at ./Base.jl:377
 [7] top-level scope at none:2
 [8] eval at ./boot.jl:331 [inlined]
 [9] eval(::Expr) at ./client.jl:449
 [10] top-level scope at ./none:3
in expression starting at /home/samd1993/mimix/MicrobiomeMixedModels.jl/src/MicrobiomeMixedModels.jl:7
ERROR: LoadError: Failed to precompile MicrobiomeMixedModels [0930ccc7-16db-55b2-bbc5-5e6d0ae52009] to /home/samd1993/.julia/compiled/v1.4/MicrobiomeMixedModels/hXJHx_iiRov.ji.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] compilecache(::Base.PkgId, ::String) at ./loading.jl:1272
 [3] _require(::Base.PkgId) at ./loading.jl:1029
 [4] require(::Base.PkgId) at ./loading.jl:927
 [5] require(::Module, ::Symbol) at ./loading.jl:922
 [6] include(::Module, ::String) at ./Base.jl:377
 [7] exec_options(::Base.JLOptions) at ./client.jl:288
 [8] _start() at ./client.jl:484
in expression starting at /home/samd1993/mimix/scripts/sim-mcmc.jl:5

Any ideas?

samd1993 avatar Jul 01 '20 00:07 samd1993