10.3 Search path

More motivation for namespace

10.3.1 Function lookup for user code

Where does R look for an object?

  1. The global environment.
  2. The packages that have been attached in reverse order.
  3. Autoloads.
  4. The base environment.

Adding another package changes the search path, but fortunately this is not applicable to package code.

10.3.2 Function lookup inside a package

Advanced section developed from Advanced R chapter on environments.

Two environments:

  1. Package environment: external interface with parent determined by search path and exposes exported objects.
  2. Namespace environment: internal interface including all objects in package.

Every namespace environment has the same ancestors:

  • imports environment: controlled by NAMESPACE file
  • base namespace: base environment bindings
  • global environment