找回密码
 注册
查看: 1659|回复: 0

R语言:ns-hooks()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 20:22:23 | 显示全部楼层 |阅读模式
ns-hooks(base)
ns-hooks()所属R语言包:base

                                        Hooks for Namespace Events
                                         为命名空间活动的钩子

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Packages can supply functions to be called when loaded, attached, detached or unloaded.
软件包可以提供的功能被称为加载时,附加,分离或卸载。


用法----------Usage----------


.onLoad(libname, pkgname)
.onAttach(libname, pkgname)
.onUnload(libpath)
.Last.lib(libpath)



参数----------Arguments----------

参数:libname
a character string giving the library directory where the package defining the namespace was found.
字符串库目录定义的命名空间的包被发现。


参数:pkgname
a character string giving the name of the package.
给人的包的名称字符串。


参数:libpath
a character string giving the complete path to the package.
包的完整路径字符串。


Details

详情----------Details----------

After loading, loadNamespace looks for a hook function named .onLoad and calls it (with two unnamed arguments) before sealing the namespace and processing exports.
加载后,loadNamespace看起来命名为一个钩子功能.onLoad,并调用它之前密封的命名空间和加工出口(与两个未命名的参数)。

When the package is attached (via library or attachNamespace), the hook function .onAttach is looked for and if found is called (with two unnamed arguments) before the package environment is sealed.
当包连接(通过library或attachNamespace),钩子函数.onAttach寻找,如果发现被称为(两个未命名参数)前密封包环境。

If a function .Last.lib is exported in the package, it will be called (with a single argument) when the package is detached. Beware that it might be called if .onAttach has failed, so it should be written defensively.  (It is called within try, so errors will not stop the package being detached.)
如果一个函数.Last.lib包中导出的,它会被称为(一个参数)时,包被分离。谨防它可能被称为.onAttach如果已失败,所以它应该被写入防守。 (这就是所谓的内try,这样的错误不会停止包被分离的。)

If a namespace is unloaded (via unloadNamespace), a hook function .onUnload is run (with a single argument) before final unloading.
如果卸载命名空间(通过unloadNamespace),一个钩子函数.onUnload运行前最后卸载(一个参数)。

Note that the code in .onLoad and .onUnload is run without the package being on the search path, but (unless circumvented) lexical scope will make objects in the namespace and its imports visible.  (Do not use the double colon operator in .onLoad as exports have not been processed at the point it is run.)
请注意,代码中的.onLoad和.onUnload没有搜索路径上的包,但运行(除非规避)词法范围将命名空间中的对象,其进口可见。 (不要使用.onLoad作为出口尚未处理的点,它运行的双冒号操作符。)

.onLoad, .onUnload and .onAttach are looked for as internal objects in the namespace and should not be exported (whereas .Last.lib should be).
.onLoad,.onUnload和.onAttach寻找命名空间中的内部对象,不应出口(而.Last.lib应该)。

Anything needed for the functioning of the namespace should be handled at load/unload times by the .onLoad and .onUnload hooks.  For example, DLLs can be loaded (unless done by a useDynLib directive in the "NAMESPACE" file) and initialized in .onLoad and unloaded in .onUnload.  Use .onAttach only for actions that are needed only when the package becomes visible to the user (for example a start-up message) or need to be run after the package environment has been created.
应处理命名空间的运作需要什么,在加载/卸载.onLoad和.onUnload挂钩倍。例如,可以被加载的DLL(除非useDynLibNAMESPACE文件中的指令完成)和初始化.onLoad和.onUnload卸载。使用.onAttach唯一的行动是必要的,只有当包变得对用户可见(例如启动的消息)或需要运行包后环境已创建。


良好做法----------Good practice----------

Loading a namespace should where possible be silent, with startup messages given by .onAttach.  These messages (and any essential ones from .onLoad) should use packageStartupMessage so they can be silenced where they would be a distraction.
载入命名空间应该在可能的情况下保持沉默,与.onAttach启动消息。这些消息(从.onLoad任何必要的),应该使用packageStartupMessage所以他们可以沉默,他们会分心。

There should be no calls to library nor require in these hooks.  The way for a package to load other packages is via the Depends field in the "DESCRIPTION" file: this ensures that the dependence is documented and packages are loaded in the correct order.  Loading a namespace should not change the search path, so rather than attach a package, dependence of a namespace on another package should be achieved by (selectively) importing from the other package's namespace.
应该没有电话library也require在这些挂钩。加载其他包一包的方式是通过Depends领域DESCRIPTION文件,这确保记录的依赖,并包以正确的顺序加载。载入命名空间应该不会改变搜索路径,因此,而不是附加软件包,应实现依赖另一个包的命名空间(选择性)导入从其他包的命名空间。

As from R 2.14.0, uses of library with argument help to display basic information about the package should use format on the computed package information object and pass this to packageStartupMessage.
从R 2.14.0,使用library说法help显示有关包的基本信息,应该使用format电脑包信息对象,并通过本packageStartupMessage 。


参见----------See Also----------

setHook shows how users can set hooks on the same events, and  lists the sequence of events involving all of the hooks.
setHook显示,用户可以设置相同的事件挂钩,并列出了涉及所有挂钩的事件序列。

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 14:39 , Processed in 0.058468 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表