Reputation: 471
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).
Upvotes: 0
Views: 11826
Reputation: 36
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.
Upvotes: 2
Reputation: 1
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.
Upvotes: 0
Reputation: 471
I was able to resolve this problem with the following steps:
Reinstall R, to somewhere like C:/R
Download rtools.
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.
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.
Upvotes: 0