如何在没有管理员权限的情况下安装R包?

3
这是一个非常普遍的问题,通常人们会问。然而,迄今为止,没有任何现有答案能够帮助我。 我正在使用Windows 7,已经在我的计算机上安装了R,但是我无法安装任何软件包。 我尝试按照这里所说的去做,但对于我来说,不仅是编程文件被阻止了,而且是只能成为用户的root。 例如,当我尝试安装软件包时,我会得到以下提示:
> install.packages("ggplot2")
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://cran.mirror.garr.it/mirrors/CRAN/src/contrib
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/src/contrib
Warning: unable to access index for repository http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/3.2
Warning messages:
1: In open.connection(con, "r") :
  unable to connect to 'cran.r-project.org' on port 80.
2: package ‘ggplot2’ is not available (for R version 3.2.0) 

如果我按照以下步骤操作,我不确定是否真正安装了该软件包。

例如:

> setInternet2(TRUE) 
> install.packages("devtools")
also installing the dependencies ‘mime’, ‘R6’, ‘bitops’, ‘brew’, ‘httr’, ‘RCurl’, ‘memoise’, ‘whisker’, ‘evaluate’, ‘rstudioapi’, ‘jsonlite’, ‘roxygen2’

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/mime_0.3.zip'
Content type 'application/zip' length 35053 bytes (34 KB)
downloaded 34 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/R6_2.0.1.zip'
Content type 'application/zip' length 123320 bytes (120 KB)
downloaded 120 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/bitops_1.0-6.zip'
Content type 'application/zip' length 36011 bytes (35 KB)
downloaded 35 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/brew_1.0-6.zip'
Content type 'application/zip' length 104709 bytes (102 KB)
downloaded 102 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/httr_0.6.1.zip'
Content type 'application/zip' length 388330 bytes (379 KB)
downloaded 379 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/RCurl_1.95-4.6.zip'
Content type 'application/zip' length 2703282 bytes (2.6 MB)
downloaded 2.6 MB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/memoise_0.2.1.zip'
Content type 'application/zip' length 16861 bytes (16 KB)
downloaded 16 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/whisker_0.3-2.zip'
Content type 'application/zip' length 64626 bytes (63 KB)
downloaded 63 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/evaluate_0.7.zip'
Content type 'application/zip' length 36884 bytes (36 KB)
downloaded 36 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/rstudioapi_0.3.1.zip'
Content type 'application/zip' length 27315 bytes (26 KB)
downloaded 26 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/jsonlite_0.9.16.zip'
Content type 'application/zip' length 1009930 bytes (986 KB)
downloaded 986 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/roxygen2_4.1.1.zip'
Content type 'application/zip' length 598652 bytes (584 KB)
downloaded 584 KB

trying URL 'http://cran.mirror.garr.it/mirrors/CRAN/bin/windows/contrib/3.2/devtools_1.7.0.zip'
Content type 'application/zip' length 309378 bytes (302 KB)
downloaded 302 KB

package ‘mime’ successfully unpacked and MD5 sums checked
package ‘R6’ successfully unpacked and MD5 sums checked
package ‘bitops’ successfully unpacked and MD5 sums checked
package ‘brew’ successfully unpacked and MD5 sums checked
package ‘httr’ successfully unpacked and MD5 sums checked
package ‘RCurl’ successfully unpacked and MD5 sums checked
package ‘memoise’ successfully unpacked and MD5 sums checked
package ‘whisker’ successfully unpacked and MD5 sums checked
package ‘evaluate’ successfully unpacked and MD5 sums checked
package ‘rstudioapi’ successfully unpacked and MD5 sums checked
package ‘jsonlite’ successfully unpacked and MD5 sums checked
package ‘roxygen2’ successfully unpacked and MD5 sums checked
package ‘devtools’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\ex3446\AppData\Local\Temp\RtmpOYDKSd\downloaded_packages

有任何建议吗?


我在工作电脑上不是管理员,每当我使用install.packages()时,默认安装到我的用户AppData文件夹中。这可能与你的R设置有关。 - Alex A.
1
@Alex A. 我发布了一个错误示例,你知道如何解决吗?那么你是如何安装你的包的? - user1267127
7
似乎是网络访问问题(可能与管理员权限有关,但似乎不太可能...),而不是写入权限问题? - Ben Bolker
1
可能需要调整一些代理设置。 - Ken Yeoh
@Ben Bolker 感谢您的评论,是的,没错。 - user1267127
显示剩余2条评论
2个回答

2
我认为这不是写入权限问题,正如其他人所评论的那样。你需要确保你的R环境设置正确(例如没有被错误或其他原因破坏)。
此外,通过阅读这个,你可能需要在你的R可执行文件链接中设置标志--internet2并重试。
引用:
(a)通过使用标志--internet2启动R或调用setInternet2(TRUE)或在启动R时将环境变量R_WIN_INTERNET2设置为非空值来使用Windows Internet函数。
另外,你可以按以下方式指定install.packages以选择特定的存储库:
install.packages("gains", repos = "http://cran.rstudio.com", type = "source")

编辑后的帖子显示正在安装一个软件包。你还是收到了之前关于 ggplot2 的信息吗? - codingEnthusiast
是的,它显示了安装的包,但当我关闭并再次运行R时,它会说找不到包。因为它删除了所有已安装的包。 - user1267127
我猜它会删除已安装的软件包,因为你正在将它们安装在 temp 文件中。也许可以像链接提供的那样更改安装目录,然后再尝试一次? - codingEnthusiast
请问您能告诉我如何更改吗?我尝试右键单击 R 并根据属性/目标进行更改,但没有成功。 - user1267127
我的意思是你的软件包安装目录,这在你提供的链接中已经展示了如何使用.libPaths来完成。 - codingEnthusiast
1
我尝试将其设置在其他地方,但是我遇到了相同的问题。 - user1267127

0

这是 R-Studio 的问题吗?我在使用 R-Studio 安装软件包时遇到了相同的问题。尝试了所有解决方案都没有起作用。然后我切换到 R 就可以安装软件包了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接