getNamespace
Get Namespace Environment Information

Description

Retrieves the namespace environment for a given named package, and retrieves namespace information from the environment.

Usage

getNamespace(name)
getNamespaceExports(ns)
getNamespaceImports(ns)
getNamespaceName(ns)
getNamespaceUsers(ns)
getNamespaceVersion(ns)
getExportedValue(ns, name)
asNamespace(ns, base.OK = TRUE)
.getNamespace(name)

Arguments

name a character string or name giving the name of a namespace for getNamespace; a character string giving the object name for which to get the exported value for getExportedValue.
ns a namespace environment or a character string giving the name of a namespace environment.
base.OK a logical value. If FALSE, an error is generated if the specified namespace is the base namespace.
Value
getNamespacereturns a namespace environment, or stops with an error message if the namespace environment does not exist and the related package cannot be loaded successfully.
.getNamespacereturns the namespace environment for name, or NULL if no namespace by that name is loaded.
getNamespaceExportsreturns a character vector of object names exported by ns.
getNamespaceImportsreturns NULL if ns is the base namespace; otherwise, getNamespaceImports returns a list with several components. The first component name is always "base" with the logical value TRUE. The rest of the component names are the names of other namespaces that have variables imported by ns, and each component value is a character vector listing the imported variables.
getNamespaceNamereturns the character name of the specified namespace.
getNamespaceUsersreturns a character vector of namespace names that are users (and therefore dependents) of the namespace specified as ns.
getNamespaceVersionreturns the version string for the specified namespace.
getExportedValuereturns the value of the object specified as name from the namespace ns.
asNamespacereturns a namespace environment, if possible.
See Also
isNamespace, library, loadNamespace.
Examples
## all objects in a package are also defined in its namespace
varInBasePackage <- objects('package:base')[[1]]
exists(varInBasePackage, envir=getNamespace('base'))

getNamespaceExports("stats")[1:10]

getNamespaceImports("base") ## returns NULL getNamespaceImports("stats")

getNamespaceName("base") getNamespaceName("graphics")

getNamespaceUsers("base") getNamespaceUsers("graphics")

getNamespaceVersion("base") getNamespaceVersion("graphics")

getExportedValue("base", "factor") getExportedValue("stats", "lm")

## the following gives an error ## Error: 'factor' is not an exported object from 'namespace:stats' getExportedValue("stats", "factor")

asNamespace("stats") # <environment: namespace:stats> asNamespace("base") # <environment: namespace:base> asNamespace("base", base.OK=FALSE) # Error: operation not allowed on base namespace asNamespace("unknown") # error: there is no package called 'unknown'

Package base version 6.1.1-7
Package Index