2.8 Options

getOption(x) Allow the user to set and examine a variety of global options which affect the way in which R computes and displays its results. Use getOption to check default values of global options.

  • x a character string holding an option name, must be quoted in quotes
  • Can only query one option at a time. If multiple options are given, will return the value of the first option.

options(...) query and modify global options.

  • ... any options can be defined, using name = value.

    Note that you do NOT need to quote your option name here!

  • options() with no arguments returns a list with the current values of the options.

  • options("name") can be used to examine options’ current value too; return a list, whereas getOption("name") returns the value only.

    • Note that you need to quote the option name when you do queries.

    • You can query more than one options at a time.

      > options("width", "digits")
      $width
      [1] 90
      
      $digits
      [1] 7
      
      > getOption("width", "digits")
      [1] 90

?options to get the help page of global options. To check which options are available and their definitions.

Use examples

## Two ways checking default option values
> options("width")
$width
[1] 81

> getOption("width")
[1] 81

## Change option values
# use name=value
> options(width=80, digits=15) # set print width, digits to print for numeric values using name=value paris
# use a named list
> options(list(width=80, digits=15)) 

Commonly used global options:

Option Description
width Controls the maximum number of columns on a line used in printing vectors, matrices and arrays, and when filling by cat. Defaults to 80.
Don’t change this if you want to print more columns. Use options(tibble.width=400) instead.
pillar.sigfig Tibbles print numbers with three significant digits by default, switching to scientific notation if the available space is too small.
options(pillar.sigfig = 4) to increase the number of digits printed out.

options("RStudioConsoleRender.viewer_mode"="viewer_pane")

Changes the display location for R Markdown rendering output from the default behavior to the Viewer pane in RStudio.

Display Options:

  • “viewer_pane”: Shows output in RStudio’s Viewer pane (bottom-right panel)
  • “window”: Opens output in a separate popup window
  • “browser”: Opens output in your default web browser

How to Check the Current Default: You can verify the current setting (or default if not set) by running:

getOption("RStudioConsoleRender.viewer_mode")

If it returns NULL, then the system is using the built-in default behavior, which is typically the popup window approach.