|
R语言条件处理和恢复conditions()函数-中英文对照帮助文档
By MicroRbt Martinez PhD
R语言函数名:conditions()
R语言函数功能:条件处理和恢复
来自资源库:基础库(R语言自带)
conditions()函数所属R语言包:所在R包具体名称、包功能的中英文双语描述见正文后面'--所在R语言包信息--'部分。
描述-----Description-----
These functions provide a mechanism for handling unusual conditions, including errors and warnings.
这些功能提供了一种用于处理异常情况(包括错误和警告)的机制。
使用方法-----Usage-----
tryCatch(expr, ..., finally)
withCallingHandlers(expr, ...)
globalCallingHandlers(...)
signalCondition(cond)
simpleCondition(message, call = NULL)
simpleError (message, call = NULL)
simpleWarning (message, call = NULL)
simpleMessage (message, call = NULL)
errorCondition(message, ..., class = NULL, call = NULL)
warningCondition(message, ..., class = NULL, call = NULL)
## S3 method for class 'condition' S3 method for class 'condition'
as.character(x, ...)
## S3 method for class 'error' S3 method for class 'error'
as.character(x, ...)
## S3 method for class 'condition' S3 method for class 'condition'
print(x, ...)
## S3 method for class 'restart' S3 method for class 'restart'
print(x, ...)
conditionCall(c)
## S3 method for class 'condition' S3 method for class 'condition'
conditionCall(c)
conditionMessage(c)
## S3 method for class 'condition' S3 method for class 'condition'
conditionMessage(c)
withRestarts(expr, ...)
computeRestarts(cond = NULL)
findRestart(name, cond = NULL)
invokeRestart(r, ...)
tryInvokeRestart(r, ...)
invokeRestartInteractively(r)
isRestart(x)
restartDescription(r)
restartFormals(r)
suspendInterrupts(expr)
allowInterrupts(expr)
.signalSimpleWarning(msg, call)
.handleSimpleError(h, msg, call)
.tryResumeInterrupt()
参数-----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.
宾语。
参数class介绍: character string naming a condition class.
命名条件类的字符串。
参数...介绍: additional arguments; see details below.
其他参数;请参阅下面的详细信息。
详情-----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和所有内部错误信号使用的类。类似地,warning使用simpleWarning,message使用simpleMessage。具有相同名称的构造函数将描述条件的字符串作为参数和可选调用。函数conditionMessage和conditionCall是返回消息和条件调用的通用函数。
The function errorCondition and warningCondition can be used to construct error conditions of a particular class with additional fields specified as the ... argument. warningCondition is analogous for warnings.
函数errorCondition和warningCondition可用于构造带有指定为...参数的附加字段的特定类的错误条件。 warningCondition与警告类似。
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在可用...参数提供的处理程序的上下文中评估其表达式参数。然后在调用tryCatch的上下文中评估finally表达式;也就是说,当计算finally表达式时,提供给当前tryCatch调用的处理程序不处于活动状态。
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。
globalCallingHandlers establishes calling handlers globally. These handlers are only called as a last resort, after the other handlers dynamically registered with withCallingHandlers have been invoked. They are called before the error global option (which is the legacy interface for global handling of errors). Registering the same handler multiple times moves that handler on top of the stack, which ensures that it is called first. Global handlers are a good place to define a general purpose logger (for instance saving the last error object in the global workspace) or a general recovery strategy (e.g. installing missing packages via the retry_loadNamespace restart).
globalCallingHandlers在全局范围内建立调用处理程序。在调用了在withCallingHandlers动态注册的其他处理程序之后,仅将这些处理程序称为万不得已。在error全局选项(这是用于全局处理错误的旧界面)之前调用它们。多次注册同一处理程序会将该处理程序移到堆栈顶部,以确保首先调用该处理程序。全局处理程序是定义通用记录器(例如,将最后一个错误对象保存在全局工作空间中)或常规恢复策略(例如,通过retry_loadNamespace重新启动安装丢失的软件包)的好地方。
Like withCallingHandlers and tryCatch, globalCallingHandlers takes named handlers. Unlike these functions, it also has an options-like interface: you can establish handlers by passing a single list of named handlers. To unregister all global handlers, supply a single 'NULL'. The list of deleted handlers is returned invisibly. Finally, calling globalCallingHandlers without arguments returns the list of currently established handlers, visibly.
像withCallingHandlers和tryCatch一样,globalCallingHandlers也采用命名处理程序。与这些函数不同,它还具有类似于optionscc的接口:您可以通过传递命名处理程序的单个列表来建立处理程序。要注销所有全局处理程序,请提供一个“ NULL”。删除的处理程序列表将不可见地返回。最后,不带参数调用globalCallingHandlersc会明显返回当前建立的处理程序列表。
User interrupts signal a condition of class interrupt that inherits directly from class condition before executing the default interrupt action.
用户中断发出信号,表明在执行默认中断操作之前,直接从类condition继承的interrupt类的条件。
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. If no restart is found, an error is thrown.
invokeRestart将控制权转移到指定的重新启动已建立的位置,并使用作为invokeRestart附加参数的参数(如果有)调用重新启动的处理程序。 invokeRestart的restart参数可以是字符串,在这种情况下,使用findRestart查找重启。如果找不到重新启动,则会引发错误。
tryInvokeRestart is a variant of invokeRestart that returns silently when the restart cannot be found with findRestart. Because a condition of a given class might be signalled with arbitrary protocols (error, warning, etc), it is recommended to use this permissive variant whenever you are handling conditions signalled from a foreign context. For instance, invokation of a "muffleWarnings" restart should be optional because the warning might have been signalled by the user or from a different package with the stop or message protocols. Only use invokeRestart when you have control of the signalling context, or when it is a logical error if the |
|