Learn R Programming

namespace (version 0.9.1)

namespace: Create, register, obtain a reference to, and unregister namespaces

Description

User-level functions to manage namespaces not (yet) available in base R.

Usage

registerNamespace(name=NULL, env=NULL) unregisterNamespace(name=NULL) makeNamespace(name, version=NULL, lib=NULL) getRegisteredNamespace(name)

Arguments

name
string
env
namespace environment
version
version
lib
string naming the package/namespace to load

Details

registerNamespace creates a new namespace entry with the provided environment. unregisterNamespace removes an existing namespace. makeNamespace creates a new namespace. getRegisteredNamespace returns the specified namespace, or NULL if it is not loaded. (In R 2.16.0 this is just a wrapper for base::.getNamespace).

References

R-devel mailing list topic "[Rd] makeNamespace and rdyncall", Dec. 2011: https://stat.ethz.ch/pipermail/r-devel/2011-December/062838.html

R-devel mailing list topic "[Rd] rdyncall fears removal from CRAN", Aug 2012: https://stat.ethz.ch/pipermail/r-devel/2012-August/064659.html

See Also

ns-internal

Examples

Run this code

## Get a reference to the namespace for the 'base' package
getRegisteredNamespace("base")

## Create a namespace, and stuff something into it.
ns <- makeNamespace("myNamespace")
assign("test",7, env=ns)
ls(env=ns)

## Now grab a reference to the namespace we just defined
ns2 <- getNamespace("myNamespace")



## Now unregister the namespace
unregisterNamespace("myNamespace")

## Returns NULL if it is no longer defined
getRegisteredNamespace("myNamespace")


Run the code above in your browser using DataLab