Unable to load shared object on startup in RStudio only (R4.0.0 / RStudio 1.2.5042)

I am having exactly the same sort of problem described in

I am running Windows 10 Home, version 10.0.18363 Build 18363.
I have removed all prior versions of R, RStudio, Rtools, and the package library then installed
R version 4.0.0 & RStudio Version 1.2.5042.

Launching RStudio generates the following messages in the console:

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

During startup - Warning message:
package ‘stats’ in options("defaultPackages") was not found
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'D:/Program Files/R/R-4.0.0/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.

Launching R does not generate this message.

I tried the suggested
update.packages(checkBuilt=TRUE)
but there has been no change.

Like rjake, there was no library folder to overwrite.

In the post, kevinushey asks
"What is the output of:

Sys.getenv("PATH")
Sys.which("stats.dll")

This was marked as the solution but I am not yet fluent enough to see it.
What should the 'correct' values from Sys.getenv() & Sys.which() be?
How does one go about changing them if they are incorrect?

I get:

Sys.getenv("PATH")
[1] "D:\Program Files\R\R-4.0.0\bin"
Sys.which("stats.dll")
stats.dll
""

I have R.exe here: D:\Program Files\R\R-4.0.0\bin

Also:

.libPaths()
[1] "D:/Program Files/R/R-4.0.0/library"

I have stats.dll in 2 places on my system:
D:\Program Files\R\R-4.0.0\library\stats\libs\x64
D:\Program Files\R\R-4.0.0\library\stats\libs\i386

Thank you for any assistance you can offer.

Hi,

We are having precisely the same issue with a completely new R 4.0.1, RStudio and RTools40 clean installation (in a new computer).

We would appreciate any help from Rstudio.
Thanks a lot.

1 Like

I have solved the problem since my original post - although I am not quite sure which one thing eventually fixed my issues
A couple of items that were useful:
I thought I had uninstalled everything prior to making a new install attempt, but I had overlooked the .Rproflie and the .Renviron files in my default directory. I had to get rid of those.

I had to go find a machine without issues to know what the output of Sys.getenv("PATH") should look like.
For reference, R is installed on my system in D:\Program Files\R\R-4.0.1\bin, so I expect to see
"D:\Program Files\R\R-4.0.1\bin\x64" somewhere in the text returned by Sys.getenv("PATH").

If you see the wrong folder referenced, or don't see your folder referenced at all, then try the steps 1-4 from http://yizhexu.com/2017/02/r-path/:

  1. Verify R is installed in the following path: C:\Program Files\R\R-3.3.2\bin\x86
  2. Open the start menu and type in “View advanced system settings”, click on “Environment variables”
  3. Under “System variables”, select Path and click on edit.
  4. Click “New”, and add the folder address for R to there (C:\Program Files\R\R-3.3.2\bin\x86)
  5. Open windows power shell and type in Rterm or R.exe to launch R command line tool

My path variable was defined as "D:\Program Files\R\R-4.0.1\bin", instead of "C:\Program Files\R\R-3.3.2\bin\x86".

Note: if there's an incorrect environment variable, used the advanced system settings to fix it or delete it.

My steps after that:
I installed R 4.0.1. No problems.
I installed RStudio 1.3.959. No problems.

Because RStudio said I needed Rtools, I also installed Rtools40.

I did the checks recommended in jtleek's slide show: Verify Rtools installation at
http://jtleek.com/modules/01_DataScientistToolbox/02_10_rtools/#6

install.packages("devtools")
library(devtools)
find_rtools()

This should return TRUE in the console if your Rtools installation worked properly

Then I did the last few instructions from the Rtools installation page:
In R, entered:

writeLines('PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"', con = "~/.Renviron")

Restarted R, then entered:

Sys.which("make")
                              make 
"D:\\rtools40\\usr\\bin\\make.exe" 

I also tried the test of

install.packages("jsonlite", type = "source")

..which was successful.

I hope this helps!

2 Likes

Is there a way to do this without going to "View advanced system settings"? I'm on a company computer and need admin rights for that

Maybe take a look at setting them in your .Renviron file instead?
I'm suggesting it because that file was in my Documents folder (which I'm hoping you can edit), and I had it WRONG in mine.
The environment variable defined there incorrectly was the only one R would pull, and I only solved my problems after I got that incorrect variable out of the way.

Maybe try https://forum.posit.co/t/how-to-set-a-variable-in-renviron/5029?

1 Like

Thanks for your complete reply @red2.kerr

We have solved the problem this morning. In our case the solution was as easy as adding the HOME user environment variable.

In addition to this thread, I found two more threads in this community related to this problem when updating R to version 4 and/or RTools 4.0: 63265, 62958. The solution to the problem is related to the environment variables.

Nevertheless, I do not think the problem is directly related to R 4.0.1, nor 1.3.959 or even RTools 4.0. It is more a problem of Windows that cannot find some dll when trying to install some R package (stats, for instance). Discussion of similar errors can be found at:

Hope it helps.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.