简体   繁体   English

环境和名称空间之间的区别

[英]Difference between environment and namespace

I know what a namespace is from other languages but in RI just cannot find a difference between the environment and namespace. 我知道其他语言的名称空间是什么,但是在RI中只是找不到环境和名称空间之间的区别。 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? 谁能解释这个问题,因为在我读过的教程(《 R编程的艺术》等人的书中)我找不到区别吗?

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. 它被定义为指令列表,允许您从其他程序包中导入要在本地使用的函数或导出要在R中使用的函数和类。因此,如果您在程序包中创建了一个名为foo的函数,则将添加到您的命名空间,例如export(foo)以使您的函数可用。 If you want to import function from a specific package to use them in yours, you will add import(thePackage) 如果要从特定程序包导入功能以在您的程序包中使用它们,则将添加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. 您可以将其视为可以评估函数和表达式的上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM