我试着安装一个包,使用

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


当前回答

这个解决方案可能会破坏R,但这里有一个最简单的解决方案,99%的时间都有效。

你需要做的只是:

install.packages('package-name',repos='http://cran.us.r-project.org')

正如作者在这里提到的

其他回答

当我在R-3.4.1中得到相同的警告时,这就是我最终可以为安装psych软件包所做的事情

1:谷歌那个包裹。

2:手动下载,扩展名为tar.gz

3:选择“包归档文件(.zip;.tar.gz)”选项安装R中的包

4:本地浏览到下载的地方,点击安装

你可能会得到一个警告:软件包的依赖项'xyz'不可用,然后首先从存储库安装这些依赖项,然后执行步骤3-4 .

我在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下载镜像来代替我的多伦多大学下载镜像。

在R 3.2.3(2016年新发布)中有一个错误,有时会阻止它找到正确的包。解决方法是手动设置存储库:

install.packages("lubridate", dependencies=TRUE, repos='http://cran.rstudio.com/')

在其他问题中找到解决方案

这为我节省了大量调试错误的时间。在很多情况下,只是镜子过时了。该函数可以使用https://cran.rstudio.com/:安装多个包及其依赖项

packages <- function(pkg){
    new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
    if (length(new.pkg))
        install.packages(new.pkg, dependencies = TRUE, repos='https://cran.rstudio.com/')
    sapply(pkg, require, character.only = TRUE)
}

packages(c("foo", "bar", "baz"))

当我使用生物导体作为源,然后调用生物clite时,它几乎总是为我工作。例子:

source("https://bioconductor.org/biocLite.R")
biocLite("preprocessCore")