Title: | Easy Loading and Installing of Packages |
---|---|
Description: | Easily load and install multiple packages from different sources, including CRAN and GitHub. The libraries function allows you to load or attach multiple packages in the same function call. The packages function will load one or more packages, and install any packages that are not installed on your system (after prompting you). Also included is a from_import function that allows you to import specific functions from a package into the global environment. |
Authors: | Jake Sherman [aut, cre] |
Maintainer: | Jake Sherman <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-05 03:43:07 UTC |
Source: | https://github.com/jakesherman/easypackages |
Imports one or more functions from a package into the parent environment, overwriting any existing objects in the parent environment sharing the name of the function(s). The package is loaded but not attached to the search list. Inspired by Python.
from_import(package, ..., verbose = TRUE)
from_import(package, ..., verbose = TRUE)
package |
the package name (length one character vector) |
... |
one or more function names (as-is, or as a list) |
verbose |
give a warning when overwriting existing objects? TRUE by default. |
## Not run: from_import("dplyr", "select", "filter") from_import("dplyr", list("select", "filter")) ## End(Not run)
## Not run: from_import("dplyr", "select", "filter") from_import("dplyr", list("select", "filter")) ## End(Not run)
install_package() Function to install a package given a package object
install_package(pack)
install_package(pack)
pack |
a |
Installs one or more packages. Similar to utils::install.packages
, but
you may supply either package names and package_obj
objects to this
function. You can install Github packages by supplying username/repo
to this function, or username$repo
for Bitbucket packages.
install_packages(...)
install_packages(...)
... |
one or more package names or |
package_obj
allows you to supply it an install function if
the package isn't on CRAN or in a public GitHub or Bitbucket repo.
## Not run: install_packages("dplyr", "ggplot2", "rvest", "magrittr") ## End(Not run)
## Not run: install_packages("dplyr", "ggplot2", "rvest", "magrittr") ## End(Not run)
is.package_obj() Returns TRUE if obj is a package_obj object
is.package_obj(obj)
is.package_obj(obj)
obj |
an R object |
A vectorized version of the library
function that accepts one or
more package names to call library
on. Unlike library
,
the libraries
function does not use non-standard evaluation (NSE)
on its inputs, meaning that you must supply your package names as strings,
or as variables.
libraries(...)
libraries(...)
... |
one or more package names or |
You may supply either package names and package_obj
objects to this
function. You may also add ::
to the end of a package name to load
the package instead of attaching the package (this means that the package
will not be added to the search list, but will be available to access via
the ::
operator).
## Not run: libraries("dplyr", "ggplot2", "rvest", "magrittr") libraries("dplyr::", "Rdatatable/data.table") ## End(Not run)
## Not run: libraries("dplyr", "ggplot2", "rvest", "magrittr") libraries("dplyr::", "Rdatatable/data.table") ## End(Not run)
load_package() Function to load a package given a package object
load_package(pack)
load_package(pack)
pack |
a |
A package object that contains at minimum the name of a package. If the package exists on CRAN, the name of the package is used to install that package from CRAN. A forward slash may be used in the package name to indicate a GitHub username and repo that a package is located in. A dollar sign may be used in the package name to indicate a Bitbucket username and repo that a package is located in.
package(name, install = utils::install.packages, ..., load_type = "attach")
package(name, install = utils::install.packages, ..., load_type = "attach")
name |
the name of a package, or, if the package is on Github, the
username and repo of the package, ex. Rdatatable/data.table, where
Rdatatable is the GitHub username, and data.table is the repo name. The
same process works with Bitbucket, except |
install |
(optional) a function used to install a package. |
... |
(optional) additional arguments to the |
load_type |
(default is "attach") should the package be loaded, or attached? See http://r-pkgs.had.co.nz/namespace.html to learn more. |
If a package is not inteded to be installed from CRAN, Github (public), or
Bitbucket (public) you may optionally supply a function to the
install
argument that installs the package, with additional arguments
to the function supplied via the ...
argument.
## Not run: this_package <- package("dplyr") github_package <- package("Rdatatable/data.table") that_package <- package("jakePackage", devtools::install_bitbucket, repo = "repo", username = "user", password = "password") ## End(Not run)
## Not run: this_package <- package("dplyr") github_package <- package("Rdatatable/data.table") that_package <- package("jakePackage", devtools::install_bitbucket, repo = "repo", username = "user", password = "password") ## End(Not run)
Loads one or more packages, and installs them after a user prompt if they
are not already installed. You may supply either package names or
package_obj
objects to this function. You can install Github packages
by supplying username/repo
to this function, or username$repo
for Bitbucket packages.
packages(..., prompt = TRUE)
packages(..., prompt = TRUE)
... |
one or more package names or |
prompt |
(default is TRUE) prompt the user before installing packages? For interactive use keeping the default makes the most sense. For interactive scripts, or scripts that you are sharing with those you trust, it may make more sense to switch this to FALSE. |
package_obj
allows you to supply it an install function if
the package isn't on CRAN or in a public GitHub or Bitbucket repo.
You may also add ::
to the end of a package name to load
the package instead of attaching the package (this means that the package
will not be added to the search list, but will be available to access via
the ::
operator).
## Not run: packages("dplyr", "ggplot2", "rvest", "magrittr") packages("dplyr::", "Rdatatable/data.table") ## End(Not run)
## Not run: packages("dplyr", "ggplot2", "rvest", "magrittr") packages("dplyr::", "Rdatatable/data.table") ## End(Not run)