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

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

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

                                        Condition Handling and Recovery
                                         条件处理和恢复

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

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

These functions provide a mechanism for handling unusual conditions, including errors and warnings.
这些功能提供了一个不寻常的条件,包括错误和警告的处理机制。


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


tryCatch(expr, ..., finally)
withCallingHandlers(expr, ...)

signalCondition(cond)

simpleCondition(message, call = NULL)
simpleError    (message, call = NULL)
simpleWarning  (message, call = NULL)
simpleMessage  (message, call = NULL)

## S3 method for class 'condition'
as.character(x, ...)
## S3 method for class 'error'
as.character(x, ...)
## S3 method for class 'condition'
print(x, ...)
## S3 method for class 'restart'
print(x, ...)

conditionCall(c)
## S3 method for class 'condition'
conditionCall(c)
conditionMessage(c)
## S3 method for class 'condition'
conditionMessage(c)

withRestarts(expr, ...)

computeRestarts(cond = NULL)
findRestart(name, cond = NULL)
invokeRestart(r, ...)
invokeRestartInteractively(r)

isRestart(x)
restartDescription(r)
restartFormals(r)

.signalSimpleWarning(msg, call)
.handleSimpleError(h, msg, call)



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

参数:c
a condition object.
条件对象。


参数:call
call expression.
致电表达。


参数:cond
a condition object.
条件对象。


参数:expr
expression to be evaluated.
表达进行评估。


参数:finally
expression to be evaluated before returning or exiting.
表达进行评估,然后返回或退出。


参数:h
function.
功能。


参数:message
character string.
字符串。


参数:msg
character string.
字符串。


参数:name
character string naming a restart.
字符串命名重启。


参数:r
restart object.
重新启动对象。


参数:x
object.
对象。


参数:...
additional arguments; see details below.
额外的参数,详见下文。


Details

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

The condition system provides a mechanism for signaling and handling unusual conditions, including errors and warnings. Conditions are represented as objects that contain information about the condition that occurred, such as a message and the call in which the condition occurred.  Currently conditions are S3-style objects, though this may eventually change.
空调系统提供了一个不寻常的条件,包括错误和警告信号和处理机制。条件表示为对象包含了有关消息和通话中发生的条件,如发生状况的信息。目前的条件是S3的样式对象,虽然这最终可能会改变。

Conditions are objects inheriting from the abstract class condition.  Errors and warnings are objects inheriting from the abstract subclasses error and warning. The class simpleError is the class used by stop and all internal error signals.  Similarly, simpleWarning is used by warning, and simpleMessage is used by message.  The constructors by the same names take a string describing the condition as argument and an optional call.  The functions conditionMessage and conditionCall are generic functions that return the message and call of a condition.
条件对象从继承抽象类的condition。错误和警告从error和warning的抽象子类继承的对象。类simpleError是stop和所有内部错误信号所使用的类。同样,simpleWarning用warning,simpleMessagemessage的使用。由相同名称的构造函数需要一个字符串作为参数和一个可选的呼叫条件。职能conditionMessage和conditionCall返回条件的消息和呼叫的通用功能。

Conditions are signaled by signalCondition.  In addition, the stop and warning functions have been modified to also accept condition arguments.
条件信号signalCondition。此外,stop和warning功能已被修改,也接受条件参数。

The function tryCatch evaluates its expression argument in a context where the handlers provided in the ... argument are available.  The finally expression is then evaluated in the context in which tryCatch was called; that is, the handlers supplied to the current tryCatch call are not active when the finally expression is evaluated.
的功能tryCatch评估在...参数提供的处理程序是可用的背景下,其表达的论点。 finally表达,然后评估,处理程序提供当前tryCatch叫不活跃时tryCatch表达在finally被称为上下文;评估。

Handlers provided in the ... argument to tryCatch are established for the duration of the evaluation of expr. If no condition is signaled when evaluating expr then tryCatch returns the value of the expression.
处理程序在...参数tryCatch中提供的是建立评价expr时间。如果没有条件进行评估时,信号expr然后tryCatch返回表达式的值。

If a condition is signaled while evaluating expr then established handlers are checked, starting with the most recently established ones, for one matching the class of the condition. When several handlers are supplied in a single tryCatch then the first one is considered more recent than the second.  If a handler is found then control is transferred to the tryCatch call that established the handler, the handler found and all more recent handlers are disestablished, the handler is called with the condition as its argument, and the result returned by the handler is returned as the value of the tryCatch call.
如果条件获得信号,而评估expr然后建立的处理程序进行检查,与最近成立的一个匹配的一流的条件,开始。当几个处理程序提供了一个单一的tryCatch然后第一个被认为是较近期第二。如果发现一个处理,然后控制权转移至tryCatch呼叫建立的处理程序,发现处理程序和所有最近的处理程序解散,称为处理程序作为它的参数条件下,由返回的结果处理程序返回作为tryCatch呼叫的价值。

Calling handlers are established by withCallingHandlers.  If a condition is signaled and the applicable handler is a calling handler, then the handler is called by signalCondition in the context where the condition was signaled but with the available handlers restricted to those below the handler called in the handler stack.  If the handler returns, then the next handler is tried; once the last handler has been tried, signalCondition returns NULL.
调用处理程序,建立withCallingHandlers。如果信号条件和适用的处理程序是调用的处理程序,然后处理程序被称为signalCondition在信号范围内,但可用的处理程序仅限于那些呼吁在处理堆栈的处理程序以下条件。如果处理程序返回,那么接下来的处理程序尝试,一旦最后的处理程序已经尝试过,signalCondition返回NULL。

User interrupts signal a condition of class interrupt that inherits directly from class condition before executing the default interrupt action.
用户中断信号一类的条件interrupt直接从类继承condition默认的中断动作之前执行。

Restarts are used for establishing recovery protocols.  They can be established using withRestarts.  One pre-established restart is an abort restart that represents a jump to top level.
重新启动用于建立恢复协议。他们可以建立使用withRestarts。是一个预先设定的重启abort重新启动,代表了最高水平的跳跃。

findRestart and computeRestarts find the available restarts.  findRestart returns the most recently established restart of the specified name.  computeRestarts returns a list of all restarts.  Both can be given a condition argument and will then ignore restarts that do not apply to the condition.
findRestart和computeRestarts找到可用的重新启动。 findRestart返回指定名称的最最近成立的重启。 computeRestarts返回所有重新启动。既可以给出一个条件参数,然后将忽略不适用的条件的重新启动。

invokeRestart transfers control to the point where the specified restart was established and calls the restart's handler with the arguments, if any, given as additional arguments to invokeRestart.  The restart argument to invokeRestart can be a character string, in which case findRestart is used to find the restart.
invokeRestart将控制转移到指定重启成立,并呼吁重新启动处理程序的参数,如果有的话,作为额外的参数给invokeRestart点。重新启动参数invokeRestart可以是一个字符串,在这种情况下,findRestart是用来寻找重新启动。

New restarts for withRestarts can be specified in several ways. The simplest is in name=function form where the function is the handler to call when the restart is invoked.  Another simple variant is as name=string where the string is stored in the description field of the restart object returned by findRestart; in this case the handler ignores its arguments and returns NULL.  The most flexible form of a restart specification is as a list that can include several fields, including handler, description, and test.  The test field should contain a function of one argument, a condition, that returns TRUE if the restart applies to the condition and FALSE if it does not; the default function returns TRUE for all conditions.
新withRestarts重新启动,可以指定在几个方面。最简单的就是在name=function形式的功能是处理程序调用时调用重启。另一种简单的变种是name=string字符串description重启findRestart返回对象的领域中,在这种情况下,处理程序将忽略它的参数,并返回NULL 。最灵活的形式的重启规范的是作为一个列表,其中可以包括多个领域,包括handler,description,test。 test字段应该包含一个参数的功能,一个条件,即返回TRUE如果重启适用的条件和FALSE如果不;默认函数返回<X >的所有条件。

One additional field that can be specified for a restart is interactive.  This should be a function of no arguments that returns a list of arguments to pass to the restart handler.  The list could be obtained by interacting with the user if necessary.  The function invokeRestartInteractively calls this function to obtain the arguments to use when invoking the restart.  The default interactive method queries the user for values for the formal arguments of the handler function.
重新启动,可用于指定一个额外的字段是interactive。这应该是一个没有参数,返回一个参数列表传递给重新启动处理程序的功能。列表中可以得到,如果有必要与用户进行交互。功能invokeRestartInteractively调用这个函数来获取参数调用启动时使用。默认interactive方法查询用户处理函数的形式参数的值。

.signalSimpleWarning and .handleSimpleError are used internally and should not be called directly.
.signalSimpleWarning和.handleSimpleError内部使用,不应直接调用。


参考文献----------References----------

error handling.  Calling handlers are based on Common Lisp and

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

stop and warning signal conditions, and try is essentially a simplified version of tryCatch.
stop和warning信号条件下,try基本上是一个简化版本tryCatch。


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


tryCatch(1, finally=print("Hello"))
e <- simpleError("test error")
## Not run: [#无法运行:]
stop(e)
tryCatch(stop(e), finally=print("Hello"))
tryCatch(stop("fred"), finally=print("Hello"))

## End(Not run)[#结束(不运行)]
tryCatch(stop(e), error = function(e) e, finally=print("Hello"))
tryCatch(stop("fred"),  error = function(e) e, finally=print("Hello"))
withCallingHandlers({ warning("A"); 1+2 }, warning = function(w) {})
## Not run: [#无法运行:]
{ withRestarts(stop("A"), abort = function() {}); 1 }

## End(Not run)[#结束(不运行)]
withRestarts(invokeRestart("foo", 1, 2), foo = function(x, y) {x + y})

##--&gt; More examples are part of[# - >更多的例子是部分]
##--&gt;   demo(error.catching)[# - 演示(error.catching)]

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


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

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-1-24 05:08 , Processed in 0.021042 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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