要从源(在 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.)
@影子的回答below还使您可以使用的情况devtools::install_version()
。这也是一个好主意,但也需要 Windows 上的 Rtools。
截至2015年9月18日,一个新的包裹versions已出现在 CRAN 上。这依赖于革命分析平均值服务器安装特定版本或日期的软件包:
# 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'))
这样做的优点是不需要 Rtools 在 Windows 上安装二进制包,但只能在 2014 年 9 月 17 日(MRAN 启动时)之前使用。
要从命令行(R 之外)安装旧版本:
您还可以使用以下命令安装包R CMD INSTALL
一旦您的计算机上本地有软件包源(“tarball”),就可以在命令行(终端、命令提示符等)上执行此操作,例如使用wget
(如果你有的话):
wget http://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_0.9.1.tar.gz
或者,如果您使用的是 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")
或者您可以通过网络浏览器从 CRAN 存档下载源代码。
要从本地文件安装,您可以执行以下操作:
R CMD INSTALL ggplot2_0.9.1.tar.gz
这应该适用于任何平台(与上面相同的警告 - 关于需要一个工具链来构建包)。
[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.