716

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

1
  • 12
    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.
    – Joris Meys
    Commented Sep 8, 2014 at 11:43

19 Answers 19

714
Answer recommended by R Language Collective

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.


11. The repository is down or does not exist

If the repository website is down or unreachable, if the hostname or directory path is incorrect, or a number of other things. These tend to give you a hint to this, something like

install.packages("quux", repos = "https://does.not.exist/CRAN")
# Installing package into ‘/home/.../...’
# (as ‘lib’ is unspecified)
# Warning: unable to access index for repository https://does.not.exist/CRAN/src/contrib:
#   cannot open URL 'https://does.not.exist/CRAN/src/contrib/PACKAGES'
# Warning: package ‘quux’ is not available for this version of R
# A version of this package for your version of R might be available elsewhere,
# see the ideas at
# https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

where the "unable to access index" suggests something is wrong there. It unfortunately does not specify what reason is stopping it. In this case, does.not.exist is not a real hostname, so a network connection cannot be created. If the hostname did exist, then the error could be because /CRAN/ is not a valid directory within the domain, the necessary PACKAGES file and indexes are not found, you do not have read permissions to them, or a number of other possible transient or permanent errors.

While the error does not give you the level of detail you need, the resolution (if this is your problem) is to use a different repository, using install.packages(., repos="https://...") (as in #10) or setting it globally with options(repos="https://...").


1
  • 1
    12. An issue with your organization's internet proxy (as in my case)
    – LulY
    Commented May 8 at 14:22
118

In the R 3.2.3 (new in 2016) there was 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

5
  • 5
    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. Commented Apr 4, 2016 at 9:59
  • Did not work for me in installing the package rbokeh. Commented Jul 6, 2021 at 5:03
  • 3
    This worked for me in R 4.2.1 on Windows. Maybe my work network somehow blocks these types of requests - I have to do something similar with Python and PIP.
    – Evan
    Commented Sep 29, 2022 at 18:12
  • This helped me installing a package on a server (i.e. not via RStudio) Commented Oct 21, 2022 at 7:30
  • This solution also works, for me for R 4.0.4. I would be great, if somebody could clarify how to troubleshoot the root cause. Commented Jun 19, 2023 at 18:04
30

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

0
25

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.

0
22
  1. Visit https://cran.r-project.org/src/contrib/Archive/.
  2. Find the package you want to install with Ctrl + F
  3. Click the package name
  4. Determine which version you want to install
  5. Open RStudio
  6. 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)
0
18

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)
    
2
  • 9
    Usually stated dependency on R version is there for a reason, it may be wise to check what such change will potentially break.
    – jangorecki
    Commented Apr 17, 2016 at 18:28
  • 1
    install.packages("local/pkg",repos=NULL) is enough Commented Oct 24, 2021 at 19:02
15

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)
2
10

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

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 .

5

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.

2
  • 1
    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'"
    – Ajay B
    Commented Jun 26, 2018 at 9:34
  • 1
    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. Commented Jul 28, 2018 at 14:56
4

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

  1. adding deb http://cran.utstat.utoronto.ca/bin/linux/ubuntu trusty/ to my /etc/apt/sources.list file
  2. Running sudo apt-get update
  3. 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.

1
  • 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.
    – Belter
    Commented Apr 27, 2017 at 5:51
3

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:[email protected]: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

3

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

3

In my case the solution was to simply upgrade R.

2

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

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")
7
  • 1
    That's only for bioconductor packages, and this is also the way bioconductor packages have to be installed.
    – Joris Meys
    Commented Jun 20, 2017 at 15:08
  • @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.
    – bli
    Commented Jun 20, 2017 at 15:20
  • 1
    @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
    Commented Jun 20, 2017 at 16:45
  • 2
    @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.
    – Joris Meys
    Commented Jun 21, 2017 at 8:57
  • 2
    @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.
    – Joris Meys
    Commented Jun 21, 2017 at 9:16
1

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.

0
0

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

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

Using library(remotes) helped me First you try to install the necessary library:

install_version("foobarbaz", "0.1.2")

Then see what dependencies are needed for it and ended with errors and also install them manually with install_version()
I was guided by the release date of my version of the language and, depending on this, installed the necessary versions of libraries

Not the answer you're looking for? Browse other questions tagged or ask your own question.