Can't Install Islr Package

Can't install ISLR package

  1. Use quotes install.packages('ISLR').
  2. Make sure your internet connection available.
  3. If you're getting package is not available as binaries, update
    your R to the current version.
  4. After successfull installation, call library('ISLR') to load
    package.

Issue with loading data from ISLR package

Just use

library(ISLR)

Then the Auto dataset becomes immediately available:

> head(Auto)
mpg cylinders displacement horsepower weight acceleration year origin name
1 18 8 307 130 3504 12.0 70 1 chevrolet chevelle malibu
2 15 8 350 165 3693 11.5 70 1 buick skylark 320
3 18 8 318 150 3436 11.0 70 1 plymouth satellite
4 16 8 304 150 3433 12.0 70 1 amc rebel sst
5 17 8 302 140 3449 10.5 70 1 ford torino
6 15 8 429 198 4341 10.0 70 1 ford galaxie 500

Please read the book carefully. This is an excerpt from page 48:

We begin by loading in the Auto data set. This data is part of the
ISLR library (we discuss libraries in Chapter 3) but to illustrate the
read.table() function we load it now from a text file. The following
command will load the Auto.data file into R and store it as an object
called Auto , in a format referred to as a data frame. (The text file
data frame can be obtained from this book’s website.
)

(Emphasis added).

Here is the link to the file that should be saved in the working directory:

http://www-bcf.usc.edu/~gareth/ISL/Auto.data

Once the file is saved with the name Auto.data in the working directory, the command

Auto <- read.table("Auto.data")

should work without any problem.

Better results will be obtained using

Auto <- read.table("Auto.data", header=TRUE)

as described later in that book.

Can I load a package's data set without installing the package?

You can do this from within R:

download.file("http://cran.r-project.org/src/contrib/ISLR_1.0.tar.gz",
dest="ISLR.tar.gz")
untar("ISLR.tar.gz",files="ISLR/data/Default.rda")
L <- load("ISLR/data/Default.rda")
summary(Default)

If you want to keep a copy of the data file:

file.copy("ISLR/data/Default.rda",".")

Clean up:

unlink(c("ISLR.tar.gz","ISLR"),recursive=TRUE)

I'm not sure you can get around having to download the tarball -- in principle you might be able to run untar() directly on a network connection, but I don't think the underlying machinery can actually extract a file without downloading the whole tarball to somewhere on your machine first.

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

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.

How to install R packages that are not available in R-essentials?

Now I have found the documentation:

This is the documentation that explains how to generate R packages that are only available in the CRAN repository:
https://www.continuum.io/content/conda-data-science

Go to the section "Building a conda R package".

(Hint: As long as the R package is available under anaconda.org use this resource. See here: https://www.continuum.io/blog/developer/jupyter-and-conda-r)

alistaire's answer is another possibility to add R packages:

If you install packages from inside of R via the regular install.packages (from CRAN mirrors), or devtools::install_github (from GitHub), they work fine. @alistaire

How to do this:
Open your (independent) R installation, then run the following command:

install.packages("png", "/home/user/anaconda3/lib/R/library")

to add new package to the correct R library used by Jupyter, otherwise the package will be installed in /home/user/R/i686-pc-linux-gnu-library/3.2/png/libs mentioned in .libPaths() .

Reading data in R from package

ISwR is the name of the package, not the datasets included in the package.

You can use data(package = "ISwR") to see the list of datasets which come with the Introductory Statistics in R package.



Related Topics



Leave a reply



Submit