安装旧版本的R软件包 [英] Installing older version of R package

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

问题描述

我正在尝试使用Rpy2和ggplot2,但是出现错误。在线搜索了一些错误之后,我发现发生错误是因为ggplot2软件包中有些更改尚未反映在Rpy2中(例如,请参阅这篇文章(编辑:链接现在已经死了))。

所以我现在需要安装一个老版本的ggplot2。这是我想要的伪代码:

  install.packages(ggplot2,version ='0.9.1') 

install.packages 没有版本参数

解决方案

从源代码安装早期版本的软件包(R ):

  packageurl<  - http://cran.r-project.org /src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
install.packages(packageurl,repos = NULL,type =source)

如果这不适用于您,而您在Windows上,原因可能是缺少构建/编译软件包的适当工具链。通常情况下,你可以从CRAN安装一个预编译的二进制文件,但它们只能对软件包 sources 进行归档,而不是二进制文件。 [1] 这意味着你需要安装 Rtools ,以便您可以在本地编译所有内容。 (注意:Rtools 不是)



@ shadow的答案下方 a>也可以使用 devtools :: install_version()。这也是一个好主意,但也需要Windows上的Rtools。



截至2015年9月18日,一个新的软件包版本已经出现在CRAN 上。这依赖于 Revolution Analytics MRAN 服务器来安装特定版本或日期的软件包:

 #安装昨天版本的检查点,按日期
install.dates('checkpoint',Sys.Date() - 1)

#安装早期版本的检查点和开发工具
install.versions(c('checkpoint','devtools'),c('0.3.3','1.6.1'))

这样做的好处是不需要Rtools在Windows上安装二进制包,但只能运行回到2014-09- 17(当MRAN启动时)。



从命令行(R之外)安装旧版本: R CMD INSTALL 来安装包(终端,命令提示符等等),例如使用 wget 在本地机器上安装软件包源代码(tarball), (如果你有的话):

  wget http://cran.r-project.org/src/contrib/Archive/ ggplot2 / ggplot2_0.9.1.tar.gz 

或者,如果您使用的是Windows, PowerShell应该是:

 (新对象System.Net.WebClient).DownloadFile(http://cran.r- project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz,./ggplot2_0.9.1.tar.gz)

或者您可以通过您的网络浏览器从CRAN存档中下载源代码。



要从本地文件安装,您可以:

  R CMD INSTALL ggplot2_0.9.1.tar.gz 

这应该适用于任何平台(使用相同的警告 - 如上所述 - 关于需要工具链来构建软件包)。






[1] 这不再是完全正确的。从2016年3月起,CRAN开始托管包含Windows的CRAN Archive服务器,适用于R的非常旧版本(> 5年)的Mac二进制文件。您现在可以使用 install.packages()从该服务器直接安装。查看新的 R FAQ 7.44 了解一些详情。


I am trying to use Rpy2 and ggplot2 but I get an error. After some searching for the error online, I found that the error occurs because there are changes in the ggplot2 package that are not yet reflected in Rpy2 (for example, see this post (Edit: Link is now dead)).

So I now need to install an older version of ggplot2. Here is pseudo-code for what I want:

install.packages("ggplot2", version='0.9.1')

But install.packages does not have a version argument. How do I do it?

解决方案

To install an older version of a package from source (within R):

packageurl <- "http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz"
install.packages(packageurl, repos=NULL, type="source")

If this doesn't work for you and you're on Windows, the reason is probably the lack of an appropriate tool chain for building/compiling packages. Normally you would install a pre-compiled binary from CRAN but they only archive package sources, not binaries.[1] This means you need to install Rtools so that you can compile everything locally. (Note: Rtools is not an R package.)

@shadow's answer below also makes the case that you can use devtools::install_version(). That's also a good idea, but is also subject to needing Rtools on Windows.

As of September 18, 2015, a new package versions has appeared on CRAN. This relies on the Revolution Analytics MRAN server to install packages for specific versions or dates:

# install yesterday's version of checkpoint, by date
install.dates('checkpoint', Sys.Date() - 1)

# install earlier versions of checkpoint and devtools
install.versions(c('checkpoint', 'devtools'), c('0.3.3', '1.6.1'))

That has the advantage of not requiring Rtools to install binary packages on Windows, but only works going back to 2014-09-17 (when MRAN was launched).

To install an older version from the command line (outside of R):

You can also install a package by using R CMD INSTALL on the command line (Terminal, Command Prompt, etc.) once you have the package source ("tarball") locally on your machine, for example using wget (if you have it):

wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz

or, if you're on Windows, an equivalent using PowerShell would be:

(new-object System.Net.WebClient).DownloadFile("http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz", "./ggplot2_0.9.1.tar.gz")

or you can just download the source from the CRAN archive via your web browser.

To install from the local file, you can just do:

R CMD INSTALL ggplot2_0.9.1.tar.gz

That should work on any platform (with the same caveat - as above - about needing a tool chain for building packages).


[1]This is no longer entirely true. From March 2016, CRAN has started hosting a "CRAN Archive" server that contains Windows and Mac binaries for very old versions of R (> 5 years old). You can now install directly from this server using install.packages(). See new R FAQ 7.44 for some details.

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

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