Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between environment and namespace

Tags:

r

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?

like image 641
ruedi Avatar asked Aug 10 '16 11:08

ruedi


1 Answers

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.

like image 138
sjakw Avatar answered Sep 17 '22 18:09

sjakw