0
votes

I've had RStudio for months now, and I've never had a problem installing packages. However, I'm no longer to install packages. And packages that I do have, like ggplot2, won't work. When I try to install, for example, glmnet, I get the following error

WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/User/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
also installing the dependencies ‘iterators’, ‘foreach’, ‘shape’

# ...

package ‘glmnet’ successfully unpacked and MD5 sums checked

And when I try to load it:

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

Error: package ‘Matrix’ could not be loaded

But the same problem happens when I try to install Matrix. I don't understand why this has happened. I've uninstalled R and Rstudio multiple times, but the problem persists. I installed Rtools and put it in the directory they want, but still nothing can be installed or loaded.

Any idea what might be happening? Not two months ago, I was able to install ggplot2 and I've been using it ever since (barring the past few days).

3
Does the file listed in the error message exist C:/Program Files/R/R-4.0.3/library/stats/libs/x64/stats.dll? What version of windows are you running? Are you on a 32 or 64 bit machine? Was this the exact same error message you were getting before you tried reinstalling R? - MrFlick
It does exist. I am running windows 10. 64 bit machine. I think it was the same error I got before reinstalling everything. Or... It was pointing to R-4.0. How do you change the directory that Rstudio installs packages? It installs packages in ```C:/Users/User/Documents/R/win-library/4.0 - mmont
Well, according to your first message it's installing package to C:/Users/User/Documents/R/win-library/4.0 (normally it's a per-user path). Only packages that come with R go to the Program Files folder. When installing you can specify a lib= path where they should install to and R looks for packages in your .libPaths(). But the unable to load library message on a core DLL is odd. Do you have some over aggressive anti virus software running? Have you tried restarting your computer? - MrFlick
I don't think I have an over-aggressive anti virus. I just restarted the computer. The problem persists. - mmont
I agree with @MrFlick, no new (non-base) packages should go into the R installation directory, ever, for many reasons. Second, though, is that on windows, paths with spaces are often very problematic (cran.r-project.org/bin/windows/base/…), I recommend installing R in a non-standard location such as c:/R/ or perhaps c:/ProgramData/R/ (not Program Files). - r2evans

3 Answers

2
votes

If the problem persists, go to C:\Program Files\R\R-4.0.3 and right click on the 'library' folder. Go to 'properties', and click on the 'security' tab. Edit the access rights to give yourself (user) rights to edit.

0
votes

I was able to resolve this problem with the following steps:

  1. Reinstall R, to somewhere like C:/R

  2. Download rtools.

  3. In RStudio, enter writeLines('PATH="C:\rtools40\usr\bin;${PATH}"', con = "~/.Renviron"). Essentially, you want to point to the bin of rtools40, which you just installed.

  4. Test that this has worked by typing, in RStudio, Sys.which("make"), which should return something like: "C:\\rtools40\\usr\\bin\\make.exe"

And that's it. Quite simple once you know the steps to take.

0
votes

Go to Settings, Update & Security, Windows Security, Virus & threat protection, Manage settings (Under Virus & threat protection settings), Manage Controlled folder access (Under Controlled folder access), Block history

Check the block history and see if there is any access blocked when you tried to install R packages. If there is, change the settings by clicking 'Controlled folder access settings' under the history detail.