require returns (invisibly) a logical indicating whether the required package is available.
library(package) and require(package) both load the namespace of the package with name package and attach it on the search list. require is designed for use inside other functions; it returns FALSE and gives a warning (rather than an error as library() does by default) if the package does not exist. Both functions check and update the list of currently attached packages and do not reload a namespace which is already loaded. (If you want to reload such a package, call detach(unload = TRUE) or unloadNamespace first.) If you want to load a package without attaching it on the search list, see requireNamespace. To suppress messages during the loading of packages use suppressPackageStartupMessages: this will suppress all messages from R itself but Not necessarily all those from package authors. If library Is called With no package Or help argument, it lists all available packages In the libraries specified by Lib.loc, And returns the corresponding information In an Object Of Class "libraryIQR". (The Structure Of this Class may change In future versions.) Use .packages(all = True) To obtain just the names Of all available packages, And installed.packages() For more information. library(help = somename) computes basic information about the package somename, And returns this in an object of class "packageInfo". (The structure of this class may change in future versions.) When used with the default value (NULL) for lib.loc, the attached packages are searched before the libraries.
Conflicts
Handling of conflicts depends on the setting of the conflicts.policy option. If this option Is Not set, then conflicts result in warning messages if the argument warn.conflicts Is TRUE. If the option Is set to the character string "strict", then all unresolved conflicts signal errors. Conflicts can be resolved using the mask.ok, exclude, And include.only arguments to library And require. Defaults for mask.ok And exclude can be specified using conflictRules. If the conflicts.policy Option Is Set To the String "depends.ok" Then conflicts resulting from attaching declared dependencies will Not produce errors, but other conflicts will. This Is likely To be the best setting For most users wanting some additional protection against unexpected conflicts. The policy can be tuned further by specifying the conflicts.policy Option As a named list With the following fields
- error: logical; if TRUE treat unresolved conflicts as errors.
- warn: logical; unless FALSE issue a warning message when conflicts are found.
- generics.ok: logical; if TRUE ignore conflicts created by defining S4 generics for functions on the search path.
- depends.ok: logical; if TRUE do Not treat conflicts with required packages as errors.
- can.mask: character vector Of names Of packages that are allowed To be masked. These would typically be base packages attached by Default.
Normally library returns (invisibly) the list of attached packages, but TRUE or FALSE if logical.return is TRUE. When called as library() it returns an object of class "libraryIQR", and for library(help=), one of class "packageInfo". require returns(invisibly) a logical indicating whether the required package Is available.