我试着安装一个包,使用

install.packages("foobarbaz")

却收到了警告

Warning message:
package 'foobarbaz' is not available (for R version x.y.z)

为什么R认为这个包是不可用的?

参见这些问题的具体例子:

My package doesn't work for R 2.15.2 package 'Rbbg' is not available (for R version 2.15.2) package is not available (for R version 2.15.2) package doMC NOT available for R version 3.0.0 warning in install.packages Dependency ‘Rglpk’ is not available for package ‘fPortfolio’ What to do when a package is not available for our R version? Is the bigvis package for R not available for R version 3.0.1? package ‘syncwave’/‘mvcwt’ is not available (for R version 3.0.2) package ‘diamonds’ is not available (for R version 3.0.0) Is the plyr package for R not available for R version 3.0.2? Package bigmemory not installing on R 64 3.0.2 package "makeR" is not available (for version 3.0.2) package ‘RTN’ is not available (for R version 3.0.1) Trouble Installing geoR package package ‘twitterR’ is not available (for R version 3.1.0) How to install 'Rcpp, package? I got "package is not available" package ‘dataset’ is not available (for R version 3.1.1) "package ‘rhipe’ is not available (for R version 3.1.2)"


当前回答

One thing that happened for me is that the version of R provided by my linux distribution (R version 3.0.2 provided by Ubuntu 14.04) was too old for the latest version of the package available on CRAN (in my case, plyr version 1.8.3 as of today). The solution was to use the packaging system of my distribution instead of trying to install from R (apt-get install r-cran-plyr got me version 1.8.1 of plyr). Maybe I could have tried to update R using updateR(), but I'm afraid that doing so would interfere with my distribution's package manager.


编辑(04/08/2020):我最近遇到了一个包(XML)的问题,据报道,在CRAN中的包更新后,我的R版本(3.6.3,Debian伸展上的最新支持)不可用。这非常出乎意料,因为我之前已经成功地安装了它(在相同的R版本和相同的操作系统上)。

由于某种原因,软件包仍然在那里,但是请安装。Packages只查看更新的(且不兼容的)版本。解决方案是找到兼容版本的URL并强制安装。使用它的包,如下:

install.packages("https://cran.r-project.org/src/contrib/Archive/XML/XML_3.99-0.3.tar.gz", repos=NULL, type="source", ask=FALSE)

其他回答

我在Ubuntu上仔细按照安装r的说明修复了这个错误,包括:

添加deb http://cran.utstat.utoronto.ca/bin/linux/ubuntu trusty/到我的/etc/apt/sources.列表文件 运行sudo apt-get update 运行sudo apt-get install r-base-dev

对于第一步,如果你愿意,你可以选择任何CRAN下载镜像来代替我的多伦多大学下载镜像。

另一个原因+解决方案

当我试图在我公司的HPC上的RStudio中安装pkgdown时,我遇到了这个错误(“包XXX对于R版本X.X.X不可用”)。

事实证明,他们在HPC上拥有的CRAN快照是2018年1月(几乎2年前)的,而且pkgdown当时确实不存在。这意味着为外行用户控制包的源代码,但作为开发人员,在大多数情况下,您可以通过以下方式更改:

## checking the specific repos you currently have
getOption("repos")

## updating your CRAN snapshot to a newer date
r <- getOption("repos")
r["newCRAN"] <- "https://cran.microsoft.com/snapshot/*2019-11-07*/"
options(repos = r)

## add newCRAN to repos you can use
setRepositories()

如果您知道您在做什么,并且可能需要多个在您的系统的CRAN中不可用的包,您可以在您的项目. rprofile中进行设置。

如果只有一个包,可能只使用install。包(“包名”,repos =“一个比你公司的旧的CRAN快照更新的CRAN”)。

访问https://cran.r-project.org/src/contrib/Archive/。 用Ctrl + F找到要安装的包 单击包名称 确定要安装的版本 打开RStudio 输入"install.packages("https://cran.r-project.org/src/contrib/Archive/[NAME OF PACKAGE]/[VERSION NUMBER].tar.gz", repos = NULL, Type ="source")"


在某些情况下,您需要提前安装几个包才能使用您想要使用的包。

例如,我需要安装7个包(Sejong, hash, rJava, tau, RSQLite, devtools, stringr)来安装KoNLP包。

install.packages('Sejong')
install.packages('hash')
install.packages('rJava')
install.packages('tau')
install.packages('RSQLite')
install.packages('devtools')
install.packages('stringr')

library(Sejong)
library(hash)
library(rJava)
library(tau)
library(RSQLite)
library(devtools)
library(stringr)

install.packages("https://cran.r-project.org/src/contrib/Archive/KoNLP/KoNLP_0.80.2.tar.gz", repos = NULL, type="source")
library(KoNLP)

有些版本的R和libcurl似乎有问题。我在Mac (R版本3.2.2)和Ubuntu (R版本3.0.2)上也遇到过同样的问题,在这两个例子中,在安装之前简单地运行这个程序就解决了。包的命令

options(download.file.method = "wget")

解决方案是由一个朋友建议的,然而,我在任何论坛上都找不到它,因此提交了这个答案给其他人。

One thing that happened for me is that the version of R provided by my linux distribution (R version 3.0.2 provided by Ubuntu 14.04) was too old for the latest version of the package available on CRAN (in my case, plyr version 1.8.3 as of today). The solution was to use the packaging system of my distribution instead of trying to install from R (apt-get install r-cran-plyr got me version 1.8.1 of plyr). Maybe I could have tried to update R using updateR(), but I'm afraid that doing so would interfere with my distribution's package manager.


编辑(04/08/2020):我最近遇到了一个包(XML)的问题,据报道,在CRAN中的包更新后,我的R版本(3.6.3,Debian伸展上的最新支持)不可用。这非常出乎意料,因为我之前已经成功地安装了它(在相同的R版本和相同的操作系统上)。

由于某种原因,软件包仍然在那里,但是请安装。Packages只查看更新的(且不兼容的)版本。解决方案是找到兼容版本的URL并强制安装。使用它的包,如下:

install.packages("https://cran.r-project.org/src/contrib/Archive/XML/XML_3.99-0.3.tar.gz", repos=NULL, type="source", ask=FALSE)