简体   繁体   English

在 R 上安装包

[英]Installing packages onto R

For some reason I am suddenly not able to install packages in R (I have subsequently updated to the latest version of R and am running Windows 7).出于某种原因,我突然无法在 R 中安装软件包(我随后更新到了最新版本的 R 并且正在运行 Windows 7)。 For example, if I type:例如,如果我输入:

install.packages('beeswarm')

Installing package into 'D:/Rlibs' (as 'lib' is unspecified) --- Please select a CRAN mirror for use in this session --- trying URL ' http://www.stats.bris.ac.uk/R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip ' Content type 'text/html' length unknown opened URL downloaded 1859 bytes将软件包安装到“D:/Rlibs”中(因为未指定“lib”)--- 请选择一个 CRAN 镜像以在此会话中使用 --- 尝试 URL ' http://www.stats.bris.ac.uk/ R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip '内容类型'text/html'长度未知打开的URL下载1859字节

Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open the connection In addition: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'beeswarm/DESCRIPTION', probable reason 'No such file or directory' read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) 中的错误:无法打开连接另外:警告消息:1:在解压缩(zipname,exdir = dest) :从 zip 文件 2 中提取错误 1:在 read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) 中:无法打开压缩文件“beeswarm/DESCRIPTION”,可能的原因'无此文件或目录'

I have read that in Windows 7 there can be important restrictions on rights to writing to certain folders etc. so I've gone to some lengths to install R and library folders in non-default areas of my computer, and to allow myself rights to certain folders, but to no avail.我已经读过,在 Windows 7 中,写入某些文件夹等的权限可能存在重要限制。某些文件夹,但无济于事。 Possibly also of importance is when I type:可能也很重要的是当我输入:

.libPaths()

# [1] "D:/Rlibs"                                             
# [2] "C:/Users/L.Halsey/Documents/R/win-library/3.0"        
# [3] "C:/Users/L.Halsey/Documents/Documents/R-3.0.1/library"

I have created several folders in an attempt to create one that I could successfully install libraries into and set them up to be recognised by R using 'environment variables' from the start button.我创建了几个文件夹,试图创建一个我可以成功地将库安装到其中的文件夹,并使用“开始”按钮中的“环境变量”将它们设置为由 R 识别。 I don't know how to delete any of them though - not sure if this is relevant to my overall problem of not now being able to install/update packages for some reason.我不知道如何删除它们中的任何一个 - 不确定这是否与我现在由于某种原因无法安装/更新软件包的整体问题有关。

The error being reported is inability to open a connection.报告的错误是无法打开连接。 In Windows that is often a firewall problem and is in the Windows R FAQ .在 Windows 中,这通常是防火墙问题,在 Windows R 常见问题解答中 The usual first attempt should be to run internet2.dll.通常的第一次尝试应该是运行 internet2.dll。 From a console session you can use:在控制台会话中,您可以使用:

setInternet2(TRUE)

(You are correct in thinking this is not due to your library setup. The error says nothing about permissions.) I don't think just typing .libPaths should return that character vector since on my machine I would need to type .libPaths() to see something like that. (你认为这不是由于你的库设置是正确的。错误没有说明权限。)我不认为只输入.libPaths应该返回那个字符向量,因为在我的机器上我需要输入.libPaths()看到类似的东西。 If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values.如果您想减少库的位置数,您可以使用.libPaths函数来设置值。 This would pick the second and third of the existing paths这将选择现有路径的第二个和第三个

 .libPaths( .libPaths()[2:3] )

The inner call retrieves the path vector and the outer call sets it to a reduced vector.内部调用检索路径向量,外部调用将其设置为缩减向量。

以管理员身份运行 RStudio 为我修复了它!

I will probably duplicate a lot of other answers on the stackoverflow, but I got exactly the same error as OP, namely: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'我可能会在 stackoverflow 上复制很多其他答案,但我得到了与 OP 完全相同的错误,即: Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'

Turned out, while I as a user had permissions to write in a certain directory, R did not.原来,虽然我作为用户有权在某个目录中写入,但 R 没有。 In order to be sure you don't have something similar, do following:为了确保您没有类似的东西,请执行以下操作:

  1. get a usb drive, let's name it E得到一个 USB 驱动器,让我们将其命名为 E
  2. download package source as a .zip file and store it onto usb-drive in some directory, let's name it E:/source将包源下载为 .zip 文件并将其存储到 USB 驱动器的某个目录中,我们将其命名为 E:/source
  3. Create directory for libraries on the usb drive, let's name it E:/libs在 USB 驱动器上为库创建目录,我们将其命名为 E:/libs
  4. Install packages calling R command install.package from the R console and setting all relevant directories to point to your usb drive:从 R 控制台调用 R 命令install.package安装包,并将所有相关目录设置为指向您的 USB 驱动器:

    (here I use package zoo as an example) (这里我以 package zoo 为例)

     install.packages("E:/source/zoo_1.7-12.zip", destdir = 'E:/source', # no "/" after the path lib = 'E:/libs', repos = NULL)
  5. Load the package from the directory, where you installed it: library('zoo', lib.loc = 'E:/libs')从安装它的目录加载包: library('zoo', lib.loc = 'E:/libs')


After you are sure, it works this way on your usb drive, you can start resolving directories permissions, and try out by changing the paths in the code above.确定后,它在您的 USB 驱动器上以这种方式工作,您可以开始解析目录权限,并通过更改上面代码中的路径来尝试。

update: In some windows environments even your usb-stick might be protected from read-write by the R. Make sure you check the permissions using the machine you are working from.更新:在某些 Windows 环境中,甚至您的 U 盘也可能受到 R 的读写保护。确保您使用正在工作的机器检查权限。

以下对我有用(基于上面的答案)

install.packages("clustvarsel", lib = "C:/Users/dnentchev/My Programs/R-3.2.2/library")

I had the same problem.我有同样的问题。 I turned the windows firewall off, and Run RStudio as administrator.我关闭了 Windows 防火墙,并以管理员身份运行 RStudio。 so, that error fixed.因此,该错误已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM