Package 'needs'

Title: Attaches and Installs Packages
Description: A simple function for easier package loading and auto-installation.
Authors: Josh Katz [aut, cre]
Maintainer: Josh Katz <[email protected]>
License: MIT + file LICENSE
Version: 0.0.3
Built: 2025-02-15 03:08:30 UTC
Source: https://github.com/joshkatz/needs

Help Index


Easier package loading / auto-installation

Description

needs is a simple R function to make package loading / installation hassle-free — use it in place of library to attach packages and automatically install any that are missing. You can also supply a minimum version number, and it will update old packages as needed. No more changing your code to reinstall packages every time you update R — needs does it for you.

Author(s)

Josh Katz

References

Source repo: http://www.github.com/joshkatz/needs


Attach/install packages

Description

needs loads and attaches packages, automatically installing (and attaching) any it can't find in your libraries. It accepts any number of arguments, given as names or character strings. Optionally, supply a minimum version on a per-package basis to update old packages as needed.

Usage

needs(..., .printConflicts = F)

Arguments

...

Packages, given as unquoted names or character strings. Specify a required package version as package = "version".

.printConflicts

Logical, specifying whether to print a summary of objects that exist in multiple places on the search path along with their respective locations. Set to TRUE to identify any masked functions. Objects in the base package and the global environment are ignored. Defaults to FALSE.

Details

Recommended use is to allow the function to autoload when prompted the first time the package is loaded interactively. To change this setting later, run needs:::autoload(TRUE) or needs:::autoload(FALSE) to turn autoloading on or off, respectively.

See Also

needs-package

Examples

## Not run: 
needs()   # returns NULL

needs(foo, bar)

# require a minimum version
needs(foo,
      bar = "0.9.1",
      baz = "0.4.3")



## End(Not run)

Re-attach packages to prevent masking

Description

prioritize detaches packages from the search path, then re-attaches them, placing them at the beginning of the search path to prevent masking. This allows for the loading of packages with conflicting function names in any order.

Usage

prioritize(...)

Arguments

...

Packages, given as unquoted names or character strings. Earlier arguments will be attached later (and therefore get a higher priority).

Details

If you find yourself calling this function a lot, you're probably doing something wrong.

Examples

## Not run: 

# loading plyr after dplyr causes badness
needs(dplyr, plyr)

# prioritize the functions in dplyr
prioritize(dplyr)


## End(Not run)

Append to Rprofile in current working directory.

Description

Exports the package functionality to .Rprofile in the current working directory. Now the same code you run can be run on another system without requiring any extra installation or throwing errors for uninstalled packages.

Usage

toProfile(dir = NULL, append = T)

Arguments

dir

Target directory for Rprofile. Defaults to working directory.

append

Whether to append to the current Rprofile, if one exists. Set to false to overwrite.

Examples

## Not run: 
toProfile()

## End(Not run)