在 R 上安装包 [英] Installing packages onto R

查看:44
本文介绍了在 R 上安装包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我突然无法在 R 中安装软件包(我随后更新到最新版本的 R 并且正在运行 Windows 7).例如,如果我输入:

install.packages('beeswarm')

<块引用>

将软件包安装到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字节

read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",类型")):无法打开连接另外:警告消息:1:在解压缩中(zipname,exdir = dest):提取时出现错误 1来自 zip 文件 2:在 read.dcf(file.path(pkgname, "DESCRIPTION"),c("Package", "Type")) : 无法打开压缩文件'beeswarm/DESCRIPTION',可能的原因'没有这样的文件或目录'

我已经读到,在 Windows 7 中,对某些文件夹的写入权限等可能存在重要限制,因此我已竭尽全力在计算机的非默认区域安装 R 和库文件夹,并允许我自己对某些文件夹的权利,但无济于事.当我输入以下内容时,可能也很重要:

.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"

我创建了几个文件夹,试图创建一个可以成功安装库的文件夹,并使用开始按钮中的环境变量"将它们设置为被 R 识别.我不知道如何删除它们中的任何一个 - 不确定这是否与我现在由于某种原因无法安装/更新软件包的整体问题有关.

解决方案

报错是无法打开连接.在 Windows 中 经常防火墙问题,位于 Windows R 常见问题解答中.通常的第一次尝试应该是运行 internet2.dll.在控制台会话中,您可以使用:

setInternet2(TRUE)

(您认为这不是由于您的库设置是正确的.该错误没有说明权限.)我不认为仅键入 .libPaths 应该返回该字符向量,因为在我的我需要输入 .libPaths() 才能看到类似的东西.如果您想减少库的位置数,您可以使用 .libPaths 函数来设置值.这将选择现有路径的第二个和第三个

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

内部调用检索路径向量,外部调用将其设置为缩减向量.

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). 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

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'

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. 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. 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. The usual first attempt should be to run 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. If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values. 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.

这篇关于在 R 上安装包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆