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

1 Like

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.

1 Like

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.

I experienced exactly the same problem when updating R from 4.3.3 to 4.4.1. Julia was still looking for the “stats” package in the 4.3.3 folder, even after I manually deleted it from there. (The error in R was unhelpful, but when run in Julia said "package ‘stats’ does not have a namespace). RCall.RHome was pointing to the wrong directory, even after a rebuild. I had removed the R_HOME environmental variables, but putting them back in was enough to get Julia and R to talk to each other both directions again.

1 Like