Learn R Programming

testextra (version 0.1.0.1)

namespaces: Create namespace environments

Description

Create and manipulate namespace and test package environments.

Usage

new_namespace_env(name, path = file.path(tempdir()),
  import = "methods")

new_pkg_environment(name = "test package environment", ..., register = FALSE)

register_namespace(ns)

unregister_namespace(ns)

is_namespace_registered(ns)

Arguments

name

The name of the environment

path

An optional path.

import

Package to include in the imports.

...

Arguments passed on to new_namespace_env

name

The name of the environment

path

An optional path.

import

Package to include in the imports.

register

Should the package namespace be registered?

ns

a namespace environment or a character name of a namespace.

Functions

  • new_namespace_env: Create a new namespace environment

  • new_pkg_environment: Create a package environment. All package environments are namespaces but not all namespaces qualify as package environments.

  • register_namespace: Register a namespace

  • unregister_namespace: Remove a namespace from the registry

  • is_namespace_registered: Check if a namespace is registered

Examples

Run this code
# NOT RUN {
ns <- new_namespace_env('my namespace')
isNamespace(ns)
environmentName(ns)
packageName(ns) # not a package

pkg <- new_pkg_environment("myPackage")
isNamespace(pkg)
environmentName(pkg)
packageName(pkg)             # now a package
is_namespace_registered(pkg) # but not registered
# }
# NOT RUN {
asNamespace("myPackage")     # so this WILL NOT work.
# }
# NOT RUN {
register_namespace(pkg)
is_namespace_registered(pkg) # now registered
asNamespace("myPackage")     # so this WILL work.

unregister_namespace(pkg)
is_namespace_registered(pkg) # now unregistered
isNamespace(pkg)             # but still a namespace

# }

Run the code above in your browser using DataLab