restart {base} | R Documentation

## Restart an Expression

### Description

`restart` performs a type of non-local return.

`try` is a user-friendly wrapper to run an expression that might fail.

### Usage

    restart(on = TRUE)
    try(expr, first = T)

### Arguments

`on` | if true a jump point is set; if false the jump point is removed
`expr` | an R expression to try
`first` | not for user use!

### Details

When `restart` is called with `on = TRUE` the evaluator marks that function as a return point. Any errors or signals (such as control-C on Unix) cause control to return to the start of the function containing the call to `restart`. The most recently established function is always entered first.

### Value

`try` returns the value of the expression if it succeeds, and an invisible object of class `"try-error"` containing the error message if it if fails. The normal error handling will print the same message unless `options("show.error.messages")` is false.

### Note

The direct use of `restart` is likely to result in an infinite loop. Use `try` unless you are sure you know what you are doing.

### See Also

`options` for setting error handlers and suppressing the printing of error messages; `geterrmessage` for retrieving the last error message.

### Examples

    ## this example will not work correctly in example(try), but
    ##  it does work correctly if pasted in
    options(show.error.messages = FALSE)
    try(log("a"))
    print(.Last.value)
    options(show.error.messages = TRUE)

[Package Contents]