Title: | Automagically Document and Install Packages Necessary to Run R Code |
---|---|
Description: | Parse R code in a given directory for R packages and attempt to install them from CRAN or GitHub. Optionally use a dependencies file for tighter control over which package versions to install. |
Authors: | Cole Brokamp [aut, cre], Steph Locke [ctb] |
Maintainer: | Cole Brokamp <[email protected]> |
License: | GPL |
Version: | 0.5.1 |
Built: | 2024-11-15 08:33:05 UTC |
Source: | https://github.com/cole-brokamp/automagic |
Searches a given directory for all R and R Markdown files, parses them for
required packages and attempts to install them from CRAN. More importantly,
if a 'deps.yaml' file was made using make_deps_file
, automagic
will use this rather than try to install based on a best guess.
automagic(directory = getwd())
automagic(directory = getwd())
directory |
folder to search for R and Rmd files |
install_package_guess
, parse_packages
get packages required to run R code
get_dependent_packages(directory = getwd())
get_dependent_packages(directory = getwd())
directory |
folder to search for R and Rmd files |
parses all R and Rmd files in a directory and uses parse_packages
to find all R packages required for the code to run
a vector of package names
Uses packageDescription
to get details about given package from R library on local machine.
Currently only supports CRAN and GitHub packages
get_package_details(pkg_name)
get_package_details(pkg_name)
pkg_name |
package name |
A list of package characteristics. "Package", "Repository", and "Version" for CRAN packages. "Package", "GithubUsername", "GithubRepo", "GithubRef", and "GithubSHA1" for Github packages.
deps.yaml
) fileInstalls packages from GitHub and CRAN based on Sha1 key and version number
respectively, as defined in a deps.yaml
file created by
make_deps_file
install_deps_file(directory = getwd())
install_deps_file(directory = getwd())
directory |
directory containing |
If a package is not available in the R library, attempt to install it from CRAN. Unlike previous versions of automagic, if the packages is not available on CRAN, the function will return an error (instead of trying to install from GitHub). If R is running interactively, then the user will be prompted before installing.
install_package_guess(pkg, force_install = FALSE, prompt = interactive())
install_package_guess(pkg, force_install = FALSE, prompt = interactive())
pkg |
a character vector with the names of packages to install from CRAN |
force_install |
install even if package is in library (warning! this could install a newer or older version of an already installed package) |
prompt |
prompt the user to install a package (defaults to yes if the R session is interactive) |
@details This function does not check package versions. Specify
force_install=TRUE
to force installation of the package, updating it
to the latest available version. Note that this function attempts to
install its packages based on a best guess and is meant for use in
automatically setting up an R programming environment. Do not use for
installing packages if you have the option to install from a deps.yaml
file.
See make_deps_file
and install_deps_file
for
installing version specific packages based on a local R library.
deps.yaml
) fileThis function parses R code for required packages using
parse_packages
and then queries the R package library to
determine the exact source and version of each package to install.
Currently, only CRAN and GitHub packages are supported.
Install packages from the 'deps.yaml' file using
automagic{install_deps_file}
make_deps_file(directory = getwd())
make_deps_file(directory = getwd())
directory |
directory containing R code to parse |
Parses an R or R Markdown file for the package names that would be required to run the code.
parse_packages(fl)
parse_packages(fl)
fl |
file to parse for required package names |
This function uses regular expressions to search through a file
containing R code to find required package names. It extracts not only
package names denoted by library
and require
, but also
packages not attached to the global namespace, but are still called with
::
or :::
.
Because it relies on regular expressions, it assumes all packages adhere to
the valid CRAN package name rules (contain only ASCII letters, numbers, and
dot; have at least two characters and start with a letter and not end it a
dot). Code is also tidying internally, making the code more predictable and
easier to parse (removes comments, adds whitespace around operators, etc).
R Markdown files are also supported by extracting only R code using
purl
.
a vector of package names as character strings
install_package_guess
, automagic
## Not run: cat('library(ggplot2)\n # library(curl)\n require(leaflet)\n CB::date_print()\n',file='temp.R') parse_packages('temp.R') unlink('temp.R') ## End(Not run)
## Not run: cat('library(ggplot2)\n # library(curl)\n require(leaflet)\n CB::date_print()\n',file='temp.R') parse_packages('temp.R') unlink('temp.R') ## End(Not run)