问题描述
我意识到有很多类似的主题是我的,但似乎没有一个能解决我的问题。从一天到下一天,我现在无法安装任何软件包。我总是收到以下错误:
> install.packages("gapminder")
Installing package into ‘C:/Users/mario/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
'lib = "C:/Users/mario/Documents/R/win-library/4.0"' is not writable
如果我选择了“改用个人图书馆”的选项,我会得到:
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/gapminder_0.3.0.zip'
Content type 'application/zip' length 2031853 bytes (1.9 MB)
downloaded 1.9 MB
Warning in install.packages :
cannot create dir 'C:\Users\mario\Documents\R\win-library\4.0\filecb869a32b3e',reason 'No such file or directory'
Error in install.packages : unable to create temporary directory ‘C:\Users\mario\Documents\R\win-library\4.0\filecb869a32b3e’
在 SO 和其他地方搜索表明这是一个权限问题。但是,我仔细检查了一下,我在管理员权限下运行 RStudio,并且我已经仔细检查过 RStudio 和 R 4.0 都具有管理员的完全读/写权限:
对于普通用户:
library 文件夹存在并且充满了我一直使用的所有库:
而且我相信这与 RStudio 无关,因为直接使用 R 并尝试从那里安装会导致相同的问题:
我运行的是 Windows 10 家庭版 10.0.19041
解决方法
在经历了太多小时的挫折之后,我找到了罪魁祸首:
关闭 Windows 安全中心的实时保护可解决此问题:
> install.packages("gapminder")
Installing package into ‘C:/Users/mario/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/gapminder_0.3.0.zip'
Content type 'application/zip' length 2031853 bytes (1.9 MB)
downloaded 1.9 MB
package ‘gapminder’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\mario\AppData\Local\Temp\RtmpGi9Jo9\downloaded_packages
这就解释了为什么这个问题一天又一天地出现(Windows 10 更新),以及为什么它没有显示在我的工作笔记本电脑上(IT 管理的更新)。现在要弄清楚如何将 R/RStudio 放在排除列表中,而不是完全关闭此选项。