Skip to content
Prev 305433 / 398506 Next

Namespaces without packages?

On Thu, Sep 13, 2012 at 6:44 PM, Ray Griner <rgriner at sdac.harvard.edu> wrote:
Global environment to be precise, but same idea.
It's a "yes, but..." sort of answer.

Put all the functions in their own environment, then attach that
environment to the search path:

E.g.,

f <- function(x) x + 2

g <- function(x) x + 5

en <- new.env()

en$f <- f
en$g <- g

attach(en)

rm(f)
rm(g)
rm(en)

f(6)
g(1:5)

but it's not necessarily a good idea... and you still have the
conflict problem you would have with packages.
Yep, they really are... in fact the trickery above is a much
simplified version of what they do.
You could do both? Let them use library() but tell them to qualify if
there's a chance of danger. Alternatively, set a hook to periodically
run conflicts() and flip out if one is found. ;-)

Cheers,

Michael