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

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

[复制链接]
发表于 2012-2-17 10:18:48 | 显示全部楼层 |阅读模式
userhooks(base)
userhooks()所属R语言包:base

                                        Functions to Get and Set Hooks for Load, Attach, Detach and Unload
                                         函数来获取和设置负载挂钩,连接,分离和卸载

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

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

These functions allow users to set actions to be taken before packages are attached/detached and namespaces are (un)loaded.
这些功能允许用户设置应采取的附加软件包之前/分离和命名空间(联合国)加载的行动。


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


getHook(hookName)
setHook(hookName, value,
        action = c("append", "prepend", "replace"))

packageEvent(pkgname,
             event = c("onLoad", "attach", "detach", "onUnload"))



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

参数:hookName
character string: the hook name
字符串:钩子名称


参数:pkgname
character string: the package/namespace name.
字符串:包/命名空间名称。


参数:event
character string: an event for the package
字符串:包事件


参数:value
A function, or for action="replace", NULL.
函数或action="replace",NULL。


参数:action
The action to be taken.  The names can be abbreviated.
应采取的行动。该名称可以是缩写。


Details

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

setHook provides a general mechanism for users to register hooks, a list of functions to be called from system (or user) functions.  The initial set of hooks was associated with events on packages/namespaces: these hooks are named via calls to packageEvent.
setHook提供了一个通用的机制,为用户注册挂钩,必须从系统功能(或用户)调用的函数的列表。初始设置的挂钩包/命名空间的事件:这些钩子通过调用packageEvent的命名。

To remove a hook completely, call setHook(hookName, NULL, "replace").
要完全删除一个钩子,调用setHook(hookName, NULL, "replace")。

When an R package is attached by library or loaded by other means, it can call initialization code.  See .onLoad for a description of the package hook functions called during initialization.  Users can add their own initialization code via the hooks provided by setHook(), functions which will be called as funname(pkgname, pkgpath) inside a try call.
当R包附在library或以其他方式加载,它可以调用初始化代码。看到.onLoad一包的钩子函数在初始化过程中调用的描述。用户可以添加自己的初始化代码通过setHook(),将funname(pkgname, pkgpath)try呼叫内调用的函数的挂钩。

The sequence of events depends on which hooks are defined, and whether a package is attached or just loaded.  In the case where all hooks are defined and a package is attached, the order of initialization  events is as follows:
事件的顺序取决于定义上的钩子,和一个包是否被附加或刚刚加载的。在所有的钩子的定义和包附的情况下,初始化事件的顺序如下:

The package namespace is loaded.
加载的包命名空间。

The package's .onLoad function is run.
运行包的.onLoad功能。

The namespace is sealed.
命名空间是密封的。

The user's "onLoad" hook is run.  
运行用户的"onLoad"钩。

The package is added to the search path.
包被添加到搜索路径。

The package's .onAttach function is run.
运行包的.onAttach功能。

The package environment is sealed.
包环境密封。

The user's "attach" hook is run.
运行用户的"attach"钩。

A similar sequence (but in reverse) is run when a package is detached and its namespace unloaded:
类似序列(但在反向)运行包时,分离和其命名空间卸载:

The user's "detach" hook is run.
运行用户的"detach"钩。

The package's .Last.lib function is run.
运行包的.Last.lib功能。

The package is removed from the search path.  
包是从搜索路径中删除。

The user's "onUnload" hook is run.  
运行用户的"onUnload"钩。

The package's .onUnload function is run.
运行包的.onUnload功能。

The package namespace is unloaded.
卸载的包命名空间。

Note that when an R session is finished, packages are not detached and namespaces are not unloaded, so the corresponding hooks will not be run.  
请注意,R会话结束时,包不沾边,不卸载命名空间,因此将不会执行相应的挂钩。

Also note that some of the user hooks are run without the package being on the search path, so in those hooks objects in the package need to be referred to using the double (or triple) colon operator, as in the example.
也注意到,一些用户挂钩的运行没有搜索路径上的包,所以在包被称为使用双(或三)冒号运算符的例子,这些挂钩对象的需要。

If multiple hooks are added, they are normally run in the order shown by getHook, but the "detach" and "onUnload" hooks are run in reverse order so the default for package events is to add hooks "inside" existing ones.
如果添加了多个挂钩,他们正在正常运行在getHook所示的顺序,但"detach"和"onUnload"钩子以相反的顺序运行,所以包事件的默认是添加钩子“内现有的。

The hooks are stored in the environment .userHooksEnv in the base package, with "mangled" names.
挂钩存储环境中的.userHooksEnv错位的名字,在基础包。


值----------Value----------

For getHook function, a list of functions (possibly empty). For setHook function, no return value. For packageEvent, the derived hook name (a character string).
getHook功能,功能列表(可能为空)。 setHook函数,没有返回值。 packageEvent,派生的钩子名称(字符串)。


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

library, detach, loadNamespace.
library,detach,loadNamespace。

See :: for a discussion of the double and triple colon operators.
看到::双重和三重结肠运营商讨论。

Other hooks may be added later: functions plot.new and persp already have them.
可以添加其他的钩子后:功能plot.new和persp已经有他们。


举例----------Examples----------


setHook(packageEvent("grDevices", "onLoad"),
        function(...) grDevices::ps.options(horizontal=FALSE))

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-23 02:17 , Processed in 0.021400 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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