when starting RStudio I get an error with stats.dll which prevents me from uploading any package

Viewed 32

I know that similar questions have been already asked on stackoverflow, but I couldn't find the exact answer to my problem.

Rstudio gives me the following error upon opening the sw:

R version 4.2.1 (2022-06-23 ucrt) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

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

I should say that Rstudio was working before I installed RTools. After installing RTools frome here, I unistalled and reinstalled RStduio multiple times, but I always get the same issue. In particular, not only I get that error on start, but I basically cannot load packages

> 2*2
[1] 4
> library(ggplot2)
Error: package or namespace load failed for ‘ggplot2’ in inDL(x, as.logical(local), as.logical(now), ...):
 unable to load shared object 'C:/Program Files/R/R-4.2.1/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module could not be found.

However, I can load packages on base R, so I don't understand what the problem is. Moreover, the package stats.dll is indeed inside the folder in the path mentioned in the error. Thus, I don't get why RStudio gives me an error. I also checked the .Renviron file on base R, which contains the following text

PATH="${RTOOLS40_HOME}\usr\bin;${C:\rtools42}"

which I accessed through base R as follows

usethis::edit_r_environ()
• Modify 'C:/Users/Sam/Documents/.Renviron'
• Restart R for changes to take effect

Please, note that I have Windows, as you might see from the file path.

Thank you for your help.

0 Answers
Related