# RCall not working - package 'stats' not found

**URL:** <https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206>\
**Category:** General Usage\
**Tags:** rcall\
**Created:** [January 19, 2023, 11:15am UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206 "2023-01-19T11:15:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danilo\_Carajiliascov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danilo_carajiliascov/32/45351_2.png) [@Danilo\_Carajiliascov](https://discourse.julialang.org/u/Danilo_Carajiliascov)\
**Post date:** [January 19, 2023, 11:15am UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/1 "2023-01-19T11:15:52Z")

</div>

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 😔

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

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 19, 2023, 12:44pm UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/2 "2023-01-19T12:44:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PhilMo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philmo/32/47317_2.png) [@PhilMo](https://discourse.julialang.org/u/PhilMo)\
**Post date:** [February 28, 2023, 7:13pm UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/3 "2023-02-28T19:13:51Z")

</div>

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

```julia
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.

```julia
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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![PhilMo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/philmo/32/47317_2.png) [@PhilMo](https://discourse.julialang.org/u/PhilMo)\
**Post date:** [February 28, 2023, 8:34pm UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/4 "2023-02-28T20:34:42Z")

</div>

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

Based on [this discussion](https://github.com/JuliaInterop/RCall.jl/issues/52), 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.

---

<div class="post-metadata">

**Author:** ![bernhard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bernhard/32/2619_2.png) [@bernhard](https://discourse.julialang.org/u/bernhard)\
**Post date:** [February 6, 2024, 6:57am UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/5 "2024-02-06T06:57:48Z")

</div>

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.

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

```

---

<div class="post-metadata">

**Author:** ![Christian\_Anderson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christian_anderson/32/211000_2.png) [@Christian\_Anderson](https://discourse.julialang.org/u/Christian_Anderson)\
**Post date:** [July 30, 2024, 4:13pm UTC](https://discourse.julialang.org/t/rcall-not-working-package-stats-not-found/93206/6 "2024-07-30T16:13:17Z")

</div>

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.
