Skip to content

NAMESPACE & methods guidance, please

3 messages · Seth Falcon, John Chambers

#
* On 2008-06-01 at 11:30 -0400 John Chambers wrote:
As described in the R News article [1], the above describes the static
component of the search mechanism, but there is a dynamic component
which adds:

    - look in .GlobalEnv
    - look in each package on the search path
    - look (again) in base

[1] http://cran.r-project.org/doc/Rnews/Rnews_2003-1.pdf
I think the dynamic lookup is important.  Consider class Foo and some
methods, like show, for working with Foo instances defined in pkgA.
Further, suppose pkgB imports pkgA and contains a function that
returns a Foo instance.

If a user class library("pkgB") at the prompt, both the developer and
the user would like for methods for dealing with Foo instances to be
available.

This has been achieved by adding pkgA to the Depends field of pkgB.
In this case, library("pkgB") has the side-effect of attaching pkgA to
the search path and Foo instances behave as desired.  This, I believe,
describes the first part of Martin's example:

Martin Morgan:
John Chambers:
I agree that using the dynamic lookup when the static lookup is
available is bad programming practice.  However, given the flexibility
of the current tools, it seems not unreasonable to expect that
picking up a method via the search path would work in a package just
as it does (should?) interactively.


+ seth