Unable to load any packages in R after installing rtools because "package 'stats' does not have a namespace"

823 Views Asked by At

Earlier today I was trying to install a package from github using the library_github command from the devtools package. However, I received an error that devtools could not be used because rtools was not installed. I tried to install rtools using the notation described directly by https://cran.r-project.org/ to install rtools for Windows 10 device. However, this never worked. I went down a rabbit hole of trying to google how to setup rtools with R that led me to uninstall, redownload R, R-Studio, and R-Tools several times. I don't remember all that I tried, but I do remember the 2 main things which I will list below.

1. The computer I am using is a Windows PC that is less than 4 months old, so much of my work up to this point has been automatically saved by Microsoft on their free Onedrive trial. I never paid much mind to it and didn't even realize all of my work and Internet downloads including my original setup of R and R-Studio had been saved on OneDrive. This hadn't been an issue until recently when my free trial space on Microsoft OneDrive ran out. As a part of this process I went and tried to move everything off of OneDrive onto my computer's hard drive. A part of this included routing my packages that I would install in R onto a folder on my hard drive as is illustrated in this link: https://medium.com/@ValidScience/how-to-fix-rstudios-package-installation-on-windows-10-c1e602bf3a1f. So while I don't think that my current installation of R is tied at all to OneDrive, I have linked my installations in R to another folder on my hard drive called RFolder.

2. When initially trying to install Rtools onto R I copied pretty much everything that this user illustrated in this video: https://www.youtube.com/watch?v=njZBf34Akgo After I completed the steps in this video, I first began to see issues with R-Studio being unable to access the stats file in R. I also began to get this error code every time that I opened 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.1.3/library/stats/libs/x64/stats.dll':
  LoadLibrary failure:  The specified module could not be found.
[Workspace loaded from ~/.RData]

When I googled this issue of LoadLibrary failure I was led to this thread https://community.rstudio.com/t/stat-package-will-not-load-after-installing-rtools/63265/11 where a user specifies a solution about deleting a hidden "./Renviron" file. I don't understand this at all and can't seem to find this file anywhere on my computer.

I have tried the simple solution of just deleting R, R-Studio, and RTools from the computer several times. However, even when I only redownload R and R-Studio and try to and try to get them to work, I am met with this same error. As it stands, I can no longer do anything in R because I cannot load any packages. I am able to install packages, but every time I try to use them with the library command I get this error:

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

Any ideas on how to fix these issues would be greatly appreciated.

1

There are 1 best solutions below

0
On

As MrFlick notes in a comment:

[You] have an Renviron file in your working directory. Check to see what’s in it and removing it. You can run readLines(".Renviron") to see the comments. Run getwd() to get the directory where that file is. On windows you’ll need to change settings to see hidden files. You can use unlink() to remove it file if necessary.

I found a .Renviron file in my default R working directory and was able to delete it. The stats package then loaded fine.