packages: packages()

Description Usage Arguments Details Examples

Description

Either loads, or installs and then loads, one or more packages from either CRAN or from public repos on Github/Bitbucket. This function is useful when sharing code with collaborators who may or may not have certain packages installed. It can also save time vs. typing out many library functions or devtools::install_github/devtools::install_bitbucket functions.

Usage

1
2
3
packages(..., install = TRUE, results = FALSE, order = "ascending")

packages_(..., install = TRUE, results = FALSE, order = "ascending")

Arguments

...

one or more package names, each seperated by a comma. You do not have to put a comma around the individual package names, though you may do so.

install

do you want to install packages that a user doesnt have installed? Default is TRUE, your other options are FALSE, or "prompt," where a user in an interactive session will be prompted as to whether or not they want packages() to install the packages for them or not.

results

Should a results table be included in output showing which packages loaded, newly_installed, or failed to do either? TRUE or FALSE, FALSE by default.

order

what order do you want to load packages into the search list? Your choices are ascending or descending, with ascending being the default. Ascending means that packages are added to the search list in the order they are inputted to the function - packages further to the right will be closer to the global environment.

Details

You also have the option of putting a double colon (::) after a package name to just install a package if it isnt installed, so that you may use :: to access functions from within the package.

While the install argument is set to TRUE by default, and will download/ install any packages specificed that you dont have, you may also change the install argument so that it prompts the user to install packages.

Examples

 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
First, lets try replicating library(pryr) with \code{packages()}:

\code{packages(pryr)}

The packages() function takes multiple package names, and may be used to
load/install multiple packages, for example:

\code{packages(pryr, data.table)}

In addition to packages from CRAN, you can install packages from public repos
on Github or Bitbucket. To install a Github package, in a string type the
GitHub username, followed by a /, followed by the repo name, like so:

\code{packages("jakesherman/jakemisc")}

For Bitbucket packages, use the "$" symbol:

\code{packages(jakesherman$jakemisc)}

Mixing CRAN and Github packages:

\code{packages(pryr, data.table, "RODBC", "jakesherman/jakemisc")}

You may also add a double colon after a package name to indicate that you
want the package to be installed, but you do not want to explicitly attach
the package. The idea here is that you are going to load the package when
you use :: to call a function from a package. See an example:

\code{packages(plyr, "dplyr::")}

Note that this function uses non-standard evaluation for the package names,
meaning that you dont need to put quotes around the names of your packages.
You may do so however if you choose, doing so wont affect the function. The
exception is that any package name with a double colon, ::, needs to be in
quotes:

\code{packages("pryr", data.table, "RODBC::", jakesherman/jakemisc)}
\code{packages(pryr, "data.table::", "RODBC::", jakesherman/jakemisc)}

You may also specify the GitHub branch to install a GitHub package from, the
default of course being the master branch. Please note that this function
cannot tell whether or not a currently installed package is the package
version of a particular GitHub branch.

\code{packages(jakesherman/jakemisc@development)}

jakesherman/jakemisc documentation built on May 18, 2019, 9:08 a.m.