[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  ns-load: Loading and Unloading Name Spaces

##  Description

Functions to load and unload name spaces.

##  Usage

    
    
    attachNamespace(ns, pos = 2L, depends = NULL, exclude, include.only)
    loadNamespace(package, lib.loc = NULL,
                  keep.source = getOption("keep.source.pkgs"),
                  partial = FALSE, versionCheck = NULL,
                  keep.parse.data = getOption("keep.parse.data.pkgs"))
    requireNamespace(package, ..., quietly = FALSE)
    loadedNamespaces()
    unloadNamespace(ns)
    isNamespaceLoaded(name)

##  Arguments

ns

string or name space object.

pos

integer specifying position to attach.

depends

` NULL ` or a character vector of dependencies to be recorded in object `
.Depends ` in the package.

package

string naming the package/name space to load.

lib.loc

character vector specifying library search path.

keep.source

Now ignored except during package installation.

keep.parse.data

Ignored except during package installation.

partial

logical; if true, stop just after loading code.

versionCheck

` NULL ` or a version specification (a list with components ` op ` and `
version ` ).

quietly

logical: should progress and error messages be suppressed?

name

string or ‘name’, see ` [ as.symbol
](/link/as.symbol?package=base&version=3.6.2) ` , of a package, e.g., `
"stats" ` .

exclude, include.only

character vectors; see ` [ library ](/link/library?package=base&version=3.6.2)
` .

…

further arguments to be passed to ` loadNamespace ` .

##  Value

` attachNamespace ` returns invisibly the package environment it adds to the
search path.

` loadNamespace ` returns the name space environment, either one already
loaded or the one the function causes to be loaded.

` requireNamespace ` returns ` TRUE ` if it succeeds or ` FALSE ` .

` loadedNamespaces ` returns a ` [ character
](/link/character?package=base&version=3.6.2) ` vector.

` unloadNamespace ` returns ` NULL ` , invisibly.

##  Details

The functions ` loadNamespace ` and ` attachNamespace ` are usually called
implicitly when ` [ library ](/link/library?package=base&version=3.6.2) ` is
used to load a name space and any imports needed. However it may be useful at
times to call these functions directly.

` loadNamespace ` loads the specified name space and registers it in an
internal data base. A request to load a name space when one of that name is
already loaded has no effect. The arguments have the same meaning as the
corresponding arguments to ` [ library
](/link/library?package=base&version=3.6.2) ` , whose help page explains the
details of how a particular installed package comes to be chosen. After
loading, ` loadNamespace ` looks for a hook function named ` [ .onLoad
](/link/.onLoad?package=base&version=3.6.2) ` as an internal variable in the
name space (it should not be exported). Partial loading is used to support
installation with lazy-loading.

Optionally the package licence is checked during loading: see section
‘Licenses’ in the help for ` [ library
](/link/library?package=base&version=3.6.2) ` .

` loadNamespace ` does not attach the name space it loads to the search path.
` attachNamespace ` can be used to attach a frame containing the exported
values of a name space to the search path (but this is almost always done
_via_ ` [ library ](/link/library?package=base&version=3.6.2) ` ). The hook
function ` [ .onAttach ](/link/.onAttach?package=base&version=3.6.2) ` is run
after the name space exports are attached.

` requireNamespace ` is a wrapper for ` loadNamespace ` analogous to ` [
require ](/link/require?package=base&version=3.6.2) ` that returns a logical
value.

` loadedNamespaces ` returns a character vector of the names of the loaded
name spaces.

` isNamespaceLoaded(pk