安装旧版本的R包

时间:2021-07-27 04:22:40

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

我正在尝试使用Rpy2和ggplot2,但是我得到了一个错误。在在线搜索错误之后,我发现出现错误是因为在ggplot2包中还没有在Rpy2中反映出来的更改(例如,请参见本文(Edit: Link现在已经失效)。

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

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

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

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

但安装。包没有版本参数。我该怎么做呢?

5 个解决方案

#1


109  

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

从源(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.)

如果这对您不起作用,并且您正在使用Windows,那么原因可能是缺少构建/编译包的适当工具链。通常,您将从CRAN安装一个预编译的二进制文件,但是它们只归档包源代码,而不是二进制文件。[1]这意味着您需要安装Rtools,以便可以在本地编译所有内容。(注意:Rtools不是R包。)

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

下面的@shadow的回答也说明了您可以使用devtools:::install_version()。这也是一个好主意,但也需要Windows上的Rtools。

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:

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

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

这样做的好处是不需要Rtools在Windows上安装二进制包,但只适用于2014-09-17 (MRAN启动时)。

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

从命令行(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):

您还可以通过在命令行(终端、命令提示符等)上使用R CMD安装来安装包,一旦您在机器上本地拥有包源(“tarball”),例如使用wget(如果有的话):

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:

或者,如果你在Windows系统上,使用PowerShell的等效方法是:

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

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

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.

[1]这已不再是完全正确的了。从2016年3月开始,CRAN开始托管一个包含Windows和Mac二进制文件的“CRAN归档”服务器,用于非常旧的R版本(> 5年前)。现在可以使用install.packages()直接从这个服务器安装。有关详细信息,请参阅新的R FAQ 7.44。

#2


55  

The devtools package offers an install_version function that can do this directly.

devtools包提供了一个install_version函数,可以直接执行此操作。

require(devtools)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")

#3


4  

Using install.packages as described in another answer does not work for me.

使用安装。另一个答案中描述的包对我不起作用。

The best alternative I found is to use function install_url from package devtools.

我发现的最佳选择是使用包devtools中的函数install_url。

Another possibility that I have not explored further:

我还没有进一步探索的另一种可能性:

  1. Download the older .tar.gz source file from the package archives.
  2. 下载旧的. tar。来自软件包档案的gz源文件。
  3. Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
  4. 按照http://rtm.wustl.edu/writings/htrtargz.pdf文件中的步骤在本地安装。

#4


4  

Found a good solution, which worked for me (the details are at the link).

找到了一个很好的解决方案,这对我很有效(细节在链接上)。

Command in "repmis" library:

命令在图书馆“repmis”:

# Install old versions of the e1071 and gtools packages.

# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")

# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)

#5


3  

You can download your appropriate version from the link below as a zip file.

您可以从以下链接下载适当的版本作为zip文件。

http://cran.r-project.org/src/contrib/Archive/ggplot2/

http://cran.r-project.org/src/contrib/Archive/ggplot2/

In R Studio: Tools >> Install packages >> Install from: (select drop down)

在R Studio: Tools >>安装包>>安装自:(选择下拉)

Package Archive File(.zip, .tar.gz).

包存档文件(。邮政,gz)。

Choose your newly-downloaded-package-zip-file and install the package

选择新下载的包zip文件并安装包

#1


109  

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

从源(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.)

如果这对您不起作用,并且您正在使用Windows,那么原因可能是缺少构建/编译包的适当工具链。通常,您将从CRAN安装一个预编译的二进制文件,但是它们只归档包源代码,而不是二进制文件。[1]这意味着您需要安装Rtools,以便可以在本地编译所有内容。(注意:Rtools不是R包。)

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

下面的@shadow的回答也说明了您可以使用devtools:::install_version()。这也是一个好主意,但也需要Windows上的Rtools。

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:

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

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

这样做的好处是不需要Rtools在Windows上安装二进制包,但只适用于2014-09-17 (MRAN启动时)。

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

从命令行(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):

您还可以通过在命令行(终端、命令提示符等)上使用R CMD安装来安装包,一旦您在机器上本地拥有包源(“tarball”),例如使用wget(如果有的话):

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:

或者,如果你在Windows系统上,使用PowerShell的等效方法是:

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

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

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.

[1]这已不再是完全正确的了。从2016年3月开始,CRAN开始托管一个包含Windows和Mac二进制文件的“CRAN归档”服务器,用于非常旧的R版本(> 5年前)。现在可以使用install.packages()直接从这个服务器安装。有关详细信息,请参阅新的R FAQ 7.44。

#2


55  

The devtools package offers an install_version function that can do this directly.

devtools包提供了一个install_version函数,可以直接执行此操作。

require(devtools)
install_version("ggplot2", version = "0.9.1", repos = "http://cran.us.r-project.org")

#3


4  

Using install.packages as described in another answer does not work for me.

使用安装。另一个答案中描述的包对我不起作用。

The best alternative I found is to use function install_url from package devtools.

我发现的最佳选择是使用包devtools中的函数install_url。

Another possibility that I have not explored further:

我还没有进一步探索的另一种可能性:

  1. Download the older .tar.gz source file from the package archives.
  2. 下载旧的. tar。来自软件包档案的gz源文件。
  3. Follow the steps documented on http://rtm.wustl.edu/writings/htrtargz.pdf to install it locally.
  4. 按照http://rtm.wustl.edu/writings/htrtargz.pdf文件中的步骤在本地安装。

#4


4  

Found a good solution, which worked for me (the details are at the link).

找到了一个很好的解决方案,这对我很有效(细节在链接上)。

Command in "repmis" library:

命令在图书馆“repmis”:

# Install old versions of the e1071 and gtools packages.

# Create vectors of the package names and versions to install
# Note the names and version numbers must be in the same order
Names <- c("e1071", "gtools")
Vers <- c("1.6", "2.6.1")

# Install old package versions into the default library
InstallOldPackages(pkgs = Names, versions = Vers)

#5


3  

You can download your appropriate version from the link below as a zip file.

您可以从以下链接下载适当的版本作为zip文件。

http://cran.r-project.org/src/contrib/Archive/ggplot2/

http://cran.r-project.org/src/contrib/Archive/ggplot2/

In R Studio: Tools >> Install packages >> Install from: (select drop down)

在R Studio: Tools >>安装包>>安装自:(选择下拉)

Package Archive File(.zip, .tar.gz).

包存档文件(。邮政,gz)。

Choose your newly-downloaded-package-zip-file and install the package

选择新下载的包zip文件并安装包