ruedi ruedi - 3 months ago 10
R Question

Difference between environment and namespace

I know what a namespace is from other languages but in R I just cannot find a difference between the environment and namespace. Could anyone explain this since in the tutorials I have read (as The Art of R Programming and others) I just cannot find a distinction?

Answer

A namespace is something specific to a package. It is defined as a list of directive that allow you to import functions from other packages to be used locally or to export your functions and classes to be used in R. So if you have created in your package a function called foo you will add to your namespace something like export(foo) to make your function usable. If you want to import function from a specific package to use them in yours, you will add import(thePackage)

The environment is simply the space where you associate names to values. You can see it as a context in which you can evaluate functions and expressions.

Comments