withOptions {R.utils}R Documentation

Evaluate an R expression with options set temporarily

Description

Evaluate an R expression with options set temporarily.

Usage

withOptions(expr, ..., args=list(), substitute=TRUE, envir=parent.frame())

Arguments

expr

The R expression to be evaluated.

...

Named options to be used.

args

(optional) Additional named options specified as a named list.

substitute

If TRUE, argument expr is substitute():ed, otherwise not.

envir

The environment in which the expression should be evaluated.

Details

Upon exit (also on errors), this function will reset all options to the state of options available upon entry. This means any options modified but also those added when evaluating expr will also be undone upon exit.

Value

Returns the results of the expression evaluated.

Author(s)

Henrik Bengtsson

See Also

Internally, eval() is used to evaluate the expression. and options() to set options.

Examples

print(pi)

# Same, i.e. using default
withOptions({
  print(pi)
})

# Printing with two digits
withOptions({
  print(pi)
}, digits=2)

# Printing with two digits then with three more
withOptions({
  print(pi)
  withOptions({
    print(pi)
  }, digits=getOption("digits")+3)
}, digits=2)

# Still printing with the default
print(pi)

[Package R.utils version 2.11.0 Index]