Information Technology Reference
In-Depth Information
Notice that you needn't enclose the package name in quotes.
The
require
function is nearly identical to
library
, but it has two features that are useful
for writing scripts. It returns
TRUE
if the package was successfully loaded and
FALSE
otherwise. It also generates a mere warning if the load fails—unlike
library
, which
generates an error.
Both functions have a key feature: they do not reload packages that are already loaded,
so calling twice for the same package is harmless. This is especially nice for writing
scripts. You can write a script to load needed packages while knowing that loaded
packages will not be reloaded:
The
detach
function will unload a package that is currently loaded.
>
detach(package:MASS)
Observe that the package name must be qualified, as in
package:MASS
.
One reason to unload a package is if it contains a function whose name conflicts with
a same-named function lower on the search list. When such a conflict occurs, we say
the higher function
masks
the lower function. You no longer “see” the lower function
because R stops searching when it finds the higher function. Hence unloading the
higher package unmasks the lower name.
See Also
See the
search
function for more about the search path.