RCall not working - package 'stats' not found

Hi, Everyone!

Can someone help me with these errors, please?

It was working yesterday at night and today mornig started to show the errors above :pensive:

After loading package (“using RCall”)
┌ Warning: RCall.jl: During startup - Warning message:
│ package ‘stats’ in options(“defaultPackages”) was not found
└ @ RCall C:\Users\danil.julia\packages\RCall\Wyd74\src\io.jl:172

After run some code:
REvalError: Error in inDL(x, as.logical(local), as.logical(now), …) :
unable to load shared object ‘C:/Users/danil/AppData/Local/Programs/R/R-4.2.2/library/stats/libs/x64/stats.dll’:
LoadLibrary failure: N�o foi poss�vel encontrar o m�dulo especificado.

Stacktrace:
[1] handle_eval_stderr(; as_warning::Bool)
@ RCall C:\Users\danil.julia\packages\RCall\Wyd74\src\io.jl:174
[2] reval_p(expr::Ptr{LangSxp}, env::Ptr{EnvSxp})
@ RCall C:\Users\danil.julia\packages\RCall\Wyd74\src\eval.jl:103
[3] reval_p(expr::Ptr{RCall.ExprSxp}, env::Ptr{EnvSxp})
@ RCall C:\Users\danil.julia\packages\RCall\Wyd74\src\eval.jl:119
[4] reval(str::String, env::RObject{EnvSxp})
@ RCall C:\Users\danil.julia\packages\RCall\Wyd74\src\eval.jl:136
[5] top-level scope
@ C:\Users\danil.julia\packages\RCall\Wyd74\src\macros.jl:71

I saw something similar. Solved it by opening up R and installing the missing package.

Hi. Just wondering if you solved this? I’ve encountered the same problem despite ‘stats’ being visible as an installed package.

using Pkg
Pkg.add("RCall")
using RCall
┌ Warning: RCall.jl: During startup - Warning message:
│ package 'stats' in options("defaultPackages") was not found
└ @ RCall C:\Users\*****\.julia\packages\RCall\Wyd74\src\io.jl:172
R"""data.frame(installed.packages())[,1] |> is.element(el = "stats")""" 
RObject{LglSxp}
[1] TRUE

I also can’t manually load the library; I see the same LoadLibrary failure you mentioned.

R"library(stats)"
ERROR: REvalError: Error: package or namespace load failed for 'stats' in inDL(x, as.logical(local), as.logical(now), ...):
 unable to load shared object 'C:/Program Files/R/R-4.2.2/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module could not be found.

But the file exists:

R"""file.exists("C:/Program Files/R/R-4.2.2/library/stats/libs/x64/stats.dll")"""
RObject{LglSxp}
[1] TRUE

Re-installing “stats” in R isn’t an option (for me) because it’s a base package (and shouldn’t be updated), loads by default (see options("defaultPackages") in R), and is installed; RCall just can’t see it or load it for some reason. (Plus, attempting to run R"""install.packages("stats")""" in Julia causes Julia to hang.)

I also have no troubles with the stats package when running R itself.

I’m running Julia v 1.8.5 on Windows; RCall v0.13.14 and R v 4.2.2. I see the error when running directly in the Julia REPL and via Jupyter lab.

Any help would be greatly appreciated.

I seem to have fixed it, though I don’t really understand how it worked.

Based on this discussion, I set my user-specific PATH Environment Variable to include both %R_HOME%\bin and %R_HOME%\bin\x64 (R_HOME was already set to the R installation root folder). RCall now loads without complaining about being unable to find the stats package.

I recently ran into this.
Using rtools 4.3 I got errors about stats.dll when using the copula package.

In my case, fixing the environment variable below helped me solve this.

@assert ENV["RTOOLS43_HOME"] == raw"C:\rtools43\usr\bin" 
R"library(copula)" #runs without errors now.