Allow the user to set and examine a variety of global options which affect the way in which R computes and displays its results.
options(…)<p></p><p>getOption(x, default = NULL)</p><p>.Options</p>
| Parameter | Description |
|---|---|
… |
any options can be defined, using name = value. However, only the ones below are used in base R. Options can also be passed by giving a single unnamed argument which is a named list. |
x |
a character string holding an option name. |
default |
if the specified option is not set in the options list, this value is returned. This facilitates retrieving an option and checking whether it is set and setting it separately if not. |
# NOT RUN {
op <- options(); utils::str(op) # op is a named list
getOption("width") == options()$width # the latter needs more memory
options(digits = 15)
pi
# set the editor, and save previous value
old.o <- options(editor = "nedit")
old.o
options(check.bounds = TRUE, warn = 1)
x <- NULL; x[4] <- "yes" # gives a warning
options(digits = 5)
print(1e5)
options(scipen = 3); print(1e5)
options(op) # reset (all) initial options
options("digits")
# }
# NOT RUN {
## set contrast handling to be like S
options(contrasts = c("contr.helmert", "contr.poly"))
# }
# NOT RUN {
# }
# NOT RUN {
## on error, terminate the R session with error status 66
options(error = quote(q("no", status = 66, runLast = FALSE)))
stop("test it")
# }
# NOT RUN {
# }
# NOT RUN {
## Set error actions for debugging:
## enter browser on error, see ?recover:
options(error = recover)
## allows to call debugger() afterwards, see ?debugger:
options(error = dump.frames)
## A possible setting for non-interactive sessions
options(error = quote({dump.frames(to.file = TRUE); q()}))
# }
# NOT RUN {
# Compare the two ways to get an option and use it
# acconting for the possibility it might not be set.
if(as.logical(getOption("performCleanp", TRUE)))
cat("do cleanup\n")
# }
# NOT RUN {
# a clumsier way of expressing the above w/o the default.
tmp <- getOption("performCleanup")
if(is.null(tmp))
tmp <- TRUE
if(tmp)
cat("do cleanup\n")
# }
# NOT RUN {
# }