ChatGPT解决这个技术问题 Extra ChatGPT

How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?

I tried to install a package, using

install.packages("foobarbaz")

but received the warning

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

Why doesn't R think that the package is available?

See also these questions referring to specific instances of this problem:

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

Note that when using RStudio, you get this warning as well when installing from another repo than CRAN. That's a bug I reported already a few times, but I don't know if it's sorted already.

3
31 revs, 8 users 92%

1. You can't spell

The first thing to test is have you spelled the name of the package correctly? Package names are case sensitive in R.

2. You didn't look in the right repository

Next, you should check to see if the package is available. Type

setRepositories()

See also ?setRepositories.

To see which repositories R will look in for your package, and optionally select some additional ones. At the very least, you will usually want CRAN to be selected, and CRAN (extras) if you use Windows, and the Bioc* repositories if you do any biological analyses.

To permanently change this, add a line like setRepositories(ind = c(1:6, 8)) to your Rprofile.site file.

3. The package is not in the repositories you selected

Return all the available packages using

ap <- available.packages()

See also Names of R's available packages, ?available.packages.

Since this is a large matrix, you may wish to use the data viewer to examine it. Alternatively, you can quickly check to see if the package is available by testing against the row names.

View(ap)
"foobarbaz" %in% rownames(ap)

Alternatively, the list of available packages can be seen in a browser for CRAN, CRAN (extras), Bioconductor, R-forge, RForge, and GitHub.

Another possible warnings message you may get when interacting with CRAN mirrors is:

Warning: unable to access index for repository

Which may indicate the selected CRAN repository is currently be unavailable. You can select a different mirror with chooseCRANmirror() and try the installation again.

There are several reasons why a package may not be available.

4. You don't want a package

Perhaps you don't really want a package. It is common to be confused about the difference between a package and a library, or a package and a dataset.

A package is a standardized collection of material extending R, e.g. providing code, data, or documentation. A library is a place (directory) where R knows to find packages it can use

To see available datasets, type

data()

5. R or Bioconductor is out of date

It may have a dependency on a more recent version of R (or one of the packages that it imports/depends upon does). Look at

ap["foobarbaz", "Depends"]

and consider updating your R installation to the current version. On Windows, this is most easily done via the installr package.

library(installr)
updateR()

(Of course, you may need to install.packages("installr") first.)

Equivalently for Bioconductor packages, you may need to update your Bioconductor installation.

source("http://bioconductor.org/biocLite.R")
biocLite("BiocUpgrade")

6. The package is out of date

It may have been archived (if it is no longer maintained and no longer passes R CMD check tests).

In this case, you can load an old version of the package using install_version()

library(remotes)
install_version("foobarbaz", "0.1.2")

An alternative is to install from the GitHub CRAN mirror.

library(remotes)
install_github("cran/foobarbaz")

7. There is no Windows/OS X/Linux binary

It may not have a Windows binary due to requiring additional software that CRAN does not have. Additionally, some packages are available only via the sources for some or all platforms. In this case, there may be a version in the CRAN (extras) repository (see setRepositories above).

If the package requires compiling code (e.g. C, C++, FORTRAN) then on Windows install Rtools or on OS X install the developer tools accompanying XCode, and install the source version of the package via:

install.packages("foobarbaz", type = "source")

# Or equivalently, for Bioconductor packages:
source("http://bioconductor.org/biocLite.R")
biocLite("foobarbaz", type = "source")

On CRAN, you can tell if you'll need special tools to build the package from source by looking at the NeedsCompilation flag in the description.

8. The package is on GitHub/Bitbucket/Gitorious

It may have a repository on GitHub/Bitbucket/Gitorious. These packages require the remotes package to install.

library(remotes)
install_github("packageauthor/foobarbaz")
install_bitbucket("packageauthor/foobarbaz")
install_gitorious("packageauthor/foobarbaz")

(As with installr, you may need to install.packages("remotes") first.)

9. There is no source version of the package

Although the binary version of your package is available, the source version is not. You can turn off this check by setting

options(install.packages.check.source = "no")

as described in this SO answer by imanuelc and the Details section of ?install.packages.

10. The package is in a non-standard repository

Your package is in a non-standard repository (e.g. Rbbg). Assuming that it is reasonably compliant with CRAN standards, you can still download it using install.packages; you just have to specify the repository URL.

install.packages("Rbbg", repos = "http://r.findata.org")

RHIPE on the other hand isn't in a CRAN-like repository and has its own installation instructions.


I Think it worth mentioning that installr works only on windows
C
Community

In the latest R (3.2.3) there is a bug, preventing it some times from finding correct package. The workaround is to set repository manually:

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

Found solution in other question


Suspected that this was the case. It appears to be a bug in r-studio however. I just tested and I don't need to set the repository if I just launch R from the terminal--only from within r-studio.
Did not work for me in installing the package rbokeh.
N
NelsonGon

This solution might break R but here is an easiest solution that works 99% of time.

You need to do is just:

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

As mentioned by the author over here


u
user2100721

There seems to be a problem with some versions of R and libcurl. I have had the same problem on Mac (R version 3.2.2) and Ubuntu (R version 3.0.2) and in both instances it was resolved simply by running this before the install.packages command

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

The solution was suggested by a friend, however, I haven't been able to find it in any of the forums, hence submitting this answer for others.


L
Lim

Visit https://cran.r-project.org/src/contrib/Archive/. Find the package you want to install with Ctrl + F Click the package name Determine which version you want to install Open RStudio Type "install.packages("https://cran.r-project.org/src/contrib/Archive/[NAME OF PACKAGE]/[VERSION NUMBER].tar.gz", repos = NULL, type="source")"

In some cases, you need to install several packages in advance to use the package you want to use.

For example, I needed to install 7 packages(Sejong, hash, rJava, tau, RSQLite, devtools, stringr) to install KoNLP package.

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)

d
dardisco

11. R (or another dependency) is out of date and you don't want to update it.

Warning this is not exactly best practice.

Download the package source.

Navigate to the DESCRIPTION file.

Remove the offending line with your text editor e.g. Depends: R (>= 3.1.1)

Install from local (i.e. from the parent directory of DESCRIPTION) e.g. install.packages("foo", type="source", repos=NULL)


Usually stated dependency on R version is there for a reason, it may be wise to check what such change will potentially break.
install.packages("local/pkg",repos=NULL) is enough
b
bli

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.

Edit (04/08/2020): I recently had an issue with a package (XML) reportedly not available for my R version (3.6.3, latest supported on Debian stretch), after an update of the package in CRAN. It was very unexpected because I already had installed it with success before (on the same version of R and same OS).

For some reason, the package was still there, but install.packages was only looking at the updated (and incompatible) version. The solution was to find the URL of the compatible version and force install.packages to use it, as follows:

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

For problems with Ubuntu, check the README: cran.r-project.org/bin/linux/ubuntu/README
This solution worked for me for debian for the package mvtnorm that ks depends on. Command was apt-get install r-cran-mvtnorm
h
hd1

This saved me a lot of time debugging what's wrong. In many cases are just mirrors out of date. This function can install multiple packages with their dependencies using 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"))

B
Biboswan

This is what I finally could do for installing psych package in R-3.4.1 when I got the same warning

1:Googled for that package.

2:downloaded it manually having tar.gz extension

3:Chose the option "Package Archive File (.zip;.tar.gz)" for install packages in R

4:browsed locally to the place where it was downloaded and clicked install

You may get a warning: dependencies 'xyz' not available for the package ,then first install those from the repository and then do steps 3-4 .


D
Damjan

I made the mistake of forgetting to put repos=NULL when installing the R package from source code. In this case the error message is slightly misleading: package 'foobarbaz' is not available (for R version x.y.z)

The problem was not the version of R, it was the repos parameter. I did install.packages('path/to/source/code/of/foobarbaz', type='source', repos=NULL) which worked for me in this occasion.

Hope this helps someone.


When I try install.packages('foobarbaz', repos=NULL) I get error " Error in install.packages("pair", repos = NULL) : type == "both" cannot be used with 'repos = NULL'"
Thanks for the comment - I think I forgot to write the type="source" parameter since I mentioned I installed this package from source code, I'll edit the answer.
A
Alex

I fixed this error on Ubuntu by carefully following the instructions for installing R. This included:

adding deb http://cran.utstat.utoronto.ca/bin/linux/ubuntu trusty/ to my /etc/apt/sources.list file Running sudo apt-get update Running sudo apt-get install r-base-dev

For step 1 you can chose any CRAN download mirror in place of my University of Toronto one if you would like.


This way do solved my problem, but still update my R to the newest version(from 3.02 to 3.4). If you want to update your R, this is a nice way.
n
nachti

I had the same problem (on Linux) which could be solved changing the proxy settings. If you are behind a proxy server check the configuration using Sys.getenv("http_proxy") within R. In my ~/.Renviron I had the following lines (from https://support.rstudio.com/hc/en-us/articles/200488488-Configuring-R-to-Use-an-HTTP-or-HTTPS-Proxy) causing the problem:

http_proxy=https://proxy.dom.com:port
http_proxy_user=user:passwd

Changing it to

http_proxy="http://user:passwd@proxy.dom.com:port"

solved the problem. You can do the same for https.

It was not the first thought when I read "package xxx is not available for r version-x-y-z" ...

HTH


S
SibyllWang

Another reason + solution

I run into this error ("package XXX is not available for R version X.X.X") when trying to install pkgdown in my RStudio on my company's HPC.

Turns out, the CRAN snapshot they have on the HPC is from Jan. 2018 (almost 2 years old) and indeed pkgdown did not exist then. That was meant to control the source of packages for layman users, but as a developer, you can in most cases change that by:

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

If you know what you are doing and may need more than one package that might not be available in your system's CRAN, you can set this up in your project .Rprofile.

If it's just one package, maybe just use install.packages("package name", repos = "a newer CRAN than your company's archaic CRAN snapshot").


P
Pablo Adames

I found a slight variation on #6 package is out of date from the excellent solution by @Richie Cotton.

Sometimes the package maintainer may show R version gaps that it does not support. In that case, you have at least two options: 1) upgrade your R version to the next one the target package already supports, 2) install the most recent version from the older ones available that would work with your R version.

A concrete example: the latest CRAN version of package rattle for data mining, 5.3.0, does not support R version 3.4 because it had a big update between package versions 5.2.0 (R >= 2.13.0) and 5.3.0 (R >=3.5).

In a case like this, the alternative to upgrading the R installation is the solution already mentioned. Install the package devtools if you don't have it (it includes package remotes) and then install the specific version that will work in your current R. You can look up that information on the CRAN page for the specific package archives.

library("devtools")
install_version("rattle", version = "5.2.0", repos = "http://cran.us.r-project.org")

F
Ferus

In my case the solution was to simply upgrade R.


T
Tunaki

It almost always works for me when I use bioconductor as source and then invoke biocLite. Example:

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

That's only for bioconductor packages, and this is also the way bioconductor packages have to be installed.
@JorisMeys It seems to me that all packages I tried to install so far were available via this method, but I'm mainly using R for bioinformatics.
@JorisMeys I don't know how, but biocLite is able to transparently fetch these packages on cran and install them. I just tested for dplyr (on Xubuntu 16.04, if that matters). Hoping to avoid mess as much as possible, I now try to install all packages "the same way" (currently using biocLite).
@bli you're right, I stand corrected. The code in biocLite recognizes the correct repos for the package and then calls install.packages() to do the actual installing. But it's not working because you use biocLite. It works because install.packages() does what it is supposed to do. There's no difference between using biocLite() and install.packages() other than the overhead and the fact that biocLite() by default also updates all other packages it deems necessary. So I'd still advise to use install.packages() for non-bioconductor packages.
@bli it doesn't guarantee compatibility, it updates everything to the latest version (unless you put suppressUpdates = TRUE). This is the same as calling update.packages() and then install.packages(). Because that's literally what biocLite does under the hood.
J
Jack Wasey

Another minor addition, while trying to test for an old R version using the docker image rocker/r-ver:3.1.0

The default repos setting is MRAN and this fails to get many packages. That version of R doesn't have https, so, for example: install.packages("knitr", repos = "https://cran.rstudio.com") seems to work.


C
Clément F

As mentioned here (in French), this can happen when you have two versions of R installed on your computer. Uninstall the oldest one, then try your package installation again! It worked fine for me.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now