Movatterモバイル変換


[0]ホーム

URL:


rdrr.io

ns-load: Loading and Unloading Name Spaces

ns-loadR Documentation

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 berecorded 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 listwith componentsop andversion).

quietly

logical: should progress and error messages be suppressed?

name

string or ‘name’, seeas.symbol,of a package, e.g.,"stats".

exclude, include.only

character vectors; seelibrary.

...

further arguments to be passed toloadNamespace.

Details

The functionsloadNamespace andattachNamespace areusually called implicitly whenlibrary is used to load a namespace and any imports needed. However it may be useful at times tocall these functions directly.

loadNamespace loads the specified name space and registers it inan internal data base. A request to load a name space when one of thatname is already loaded has no effect. The arguments have the samemeaning as the corresponding arguments tolibrary, whosehelp page explains the details of how a particular installed packagecomes to be chosen. After loading,loadNamespace looks for ahook function named.onLoad as an internal variable inthe name space (it should not be exported). Partial loading is usedto support installation with lazy-loading.

Optionally the package licence is checked during loading: see section‘Licenses’ in the help forlibrary.

loadNamespace does not attach the name space it loads to thesearch path.attachNamespace can be used to attach a framecontaining the exported values of a name space to the search path (butthis is almost always donevialibrary). Thehook function.onAttach is run after the name spaceexports are attached.

requireNamespace is a wrapper forloadNamespaceanalogous torequire that returns a logical value.

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

isNamespaceLoaded(pkg) is equivalent to but more efficient thanpkg %in% loadedNamespaces().

unloadNamespace can be used to attempt to force a name space tobe unloaded. If the name space is attached, it is firstdetached, thereby running a.onDetach or.Last.lib function in the name space if one is exported. Anerror is signaled and the name space is not unloaded if the name spaceis imported by other loaded name spaces. If defined, a hook function.onUnload is run before removing the name space from theinternal registry.

See the comments in the help fordetach about someissues with unloading and reloading name spaces.

Value

attachNamespace returns invisibly the package environment itadds to the search path.

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

requireNamespace returnsTRUE if it succeeds orFALSE.

loadedNamespaces returns acharacter vector.

unloadNamespace returnsNULL, invisibly.

Tracing

As fromR 4.1.0 the operation ofloadNamespace can be traced,which can help track down the causes of unexpected messages (includingwhich package(s) they come from sinceloadNamespace is called inmany ways including from itself and by:: and can be called byload). Setting the environment variable_R_TRACE_LOADNAMESPACE_ to a numerical value will generateadditional messages on progress. Non-zero values,e.g.1, report which namespace is being loaded and whenloading completes: values2 to4 report in increasingdetail. Negative values are reserved for tracing specific features andtheir current meanings are documented in source-code comments.

Loading standard packages is never traced.

Author(s)

Luke Tierney and R-core

References

The ‘Writing R Extensions’ manual, section “Package namespaces”.

See Also

getNamespace,asNamespace,topenv,.onLoad (etc);furtherenvironment.

Examples

 (lns <- loadedNamespaces()) statL <- isNamespaceLoaded("stats") stopifnot( identical(statL, "stats" %in% lns) ) ## The string "foo" and the symbol 'foo' can be used interchangably here: stopifnot( identical(isNamespaceLoaded(  "foo"   ), FALSE),            identical(isNamespaceLoaded(quote(foo)), FALSE),            identical(isNamespaceLoaded(quote(stats)), statL))hasS <- isNamespaceLoaded("splines") # (to restore if needed)Sns <- asNamespace("splines") # loads it if not alreadystopifnot(   isNamespaceLoaded("splines"))unloadNamespace(Sns) # unloading the NS 'object'stopifnot( ! isNamespaceLoaded("splines"))if (hasS) loadNamespace("splines") # (restoring previous state)

What can we improve?

R Package Documentation

Browse R Packages

We want your feedback!

Note that we can't provide technical support on individual packages. You should contact the package authors for that.

 
Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, readEmbedding Snippets.

Close

[8]ページ先頭

©2009-2026 Movatter.jp