What is the options() function in R?

Overview

The options() function in R is used to set and examine different global options that affects the way in which R determines and returns its results.

Syntax

The options() function takes the syntax below:

options(…)
Syntax for the options() function in R

Parameter value

The options() function takes the parameter value, ..., which represents any option that can be defined using name=value.

Below, we have a list of some options that are used in base R:

Options

result

add.smooth

TRUE

check.bounds

FALSE

continue

“+”

digits

7

echo

TRUE

encoding

“native.enc”

expressions

5000

Code

# implementing the options() function
# setting the digits option
options(digits=10)
print(10/7)
# to set the console width
options(width=100)

Explanation

  • Line 3: We set the digits option to 10 using the options() function.
  • Line 4: We obtained the result of an arithmetic operation.
  • Line 7: We set the console width to 100.

Free Resources