Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorganize installing packages #92

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ book:
- reproducible-environments.qmd
- installing-r.qmd
- maintaining-r.qmd
- install-single-package.qmd
- part: "All is Fail"
chapters:
- debugging-r.qmd
Expand Down
59 changes: 0 additions & 59 deletions install-single-package.qmd

This file was deleted.

67 changes: 66 additions & 1 deletion installing-packages.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,69 @@ Installed --"library()"--> Loaded
end
```

[R Packages](https://r-pkgs.org/Structure.html) covers these phases of the package lifecycle in much more detail.
[R Packages](https://r-pkgs.org/Structure.html) covers these phases of the package lifecycle in much more detail.

## Binary packages

- where to get them
- how to know you got them

## Source packages

The most common type of package you install is a **binary** package. Packages
released on CRAN are built as pre-compiled binaries.

However often it is useful to install packages which do not have a pre-built
binary version available. This allows you to install development versions not
yet released on CRAN, as well as older versions of released packages. It also lets
you build your own packages locally.

To install a source package you will need to [setup a development environment](#set-up-an-r-dev-environment).

There are a few main functions used to install source packages.

- `devtools::install_dev()` to install the latest development version of a CRAN package. ^[This will only work if the package includes a link to the development location in the package DESCRIPTION]
- `devtools::install_github()` to install a package directly from GitHub, even if it is not on CRAN.
- `devtools::install_version()` to install previously released CRAN versions of a package.

For example `devtools::install_dev("dplyr")` will install the development
version of dplyr. `devtools::install_github("jimhester/lookup")` will install
Jim's lookup package (which is not on CRAN), and
`devtools::install_version("readr", "1.0.0")` will install readr 1.0.0.

It is also possible to [fork, clone and work with a package
directly](https://happygitwithr.com/fork.html) then use `devtools::install()`
and `devtools::load_all()` to work with the package locally like you would with
a package you have created yourself.

## Installation to a temporary library

It is sometimes useful to install packages to a temporary library, so that they
don't affect your normal packages. This can be done by using the `lib` argument
to the devtools install functions, then using `lib.loc` in `library()` when you
load the package.

```r
library(devtools)

tmp_lib <- "~/tmp/tmp_library"
dir.create(tmp_lib)

devtools::install_github("dill/beyonce", lib = tmp_lib)

## restart R

## explicitly load the affected packages from the temporary library
library(beyonce, lib.loc = tmp_lib)

## your experimentation goes here

## done? clean up!
unlink(tmp_lib, recursive = TRUE)
```

::: {.callout-note}
[Try the activity](https://raw.githubusercontent.com/jimhester/wtf-source-package/master/01_source-package_spartan.R): `usethis::use_course("rstd.io/wtf-source-package")`

To practice installing various types of source packages.
:::