Problem Installing Packages in Rstudio

My R and Rstudio - were working fine, but recently, when I install any package in Rstudio and add library(package) I am getting following error :

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-3.6.3/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 'C:/Program Files/R/R-3.6.3/library/stats/libs/x64/stats.dll':
LoadLibrary failure: The specified module could not be found.

If tried to install package seperately in R , outside Rstudio, I am able to run it. But not able to do that in Rstudio. I tried installing Rtools, even reinstalled and tried Rstudio, but now I am getting same error message in Rstudio. - Not able to find the issue
Can anyone help me with this?

This is usually due to a PATH problem, as solved here or there.

Check the value of:

Sys.getenv("PATH")

and

Sys.which("stats.dll")

And check where R is actually installed on your system, to see if there is a discrepancy.

Thanks, I tried,

Sys.getenv("PATH")
```[1] "\\usr\\bin;"
This is the result, which is not the path of R.
I tried changing the system variable by adding the correct R path to the environment as mentioned in the solved links . 
but still, am getting same. Sys.getenv ("PATH")- result
how do I change this "PATH" directory?

Thanks, I found the solution, while installing Rtools40 - the "PATH" issue got generated. and when I tried uninstalling and reinstalling the lesser version - the PATH location got changed to usr\bin.
I now tried changing the PATH location by giving the following command;

writeLines('PATH="C:\Program Files\R\R-3.6.3\bin\x64"', con = "~/.Renviron")

It worked fine. I am not getting the "stats.dll not found" error anymore when I install packages or load any library.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.