Examples for 'R.utils::Options'


The Options class

Aliases: Options

Keywords: classes programming

### ** Examples

local <- Options()

# Query a missing option
cex <- getOption(local, "graphics/cex")
cat("graphics/cex =", cex, "\n")  # Returns NULL
graphics/cex = 
# Query a missing option with default value
cex <- getOption(local, "graphics/cex", defaultValue=1)
cat("graphics/cex =", cex, "\n")  # Returns NULL
graphics/cex = 1 
# Set option and get previous value
oldCex <- setOption(local, "graphics/cex", 2)
cat("previous graphics/cex =", oldCex, "\n")  # Returns NULL
previous graphics/cex = 
# Set option again and get previous value
oldCex <- setOption(local, "graphics/cex", 3)
cat("previous graphics/cex =", oldCex, "\n")  # Returns 2
previous graphics/cex = 2 
# Query a missing option with default value, which is ignored
cex <- getOption(local, "graphics/cex", defaultValue=1)
cat("graphics/cex =", cex, "\n")  # Returns 3
graphics/cex = 3 
# Query multiple options with multiple default values
multi <- getOption(local, c("graphics/cex", "graphics/pch"), c(1,2))
print(multi)
$`graphics/cex`
[1] 3

$`graphics/pch`
[1] 2
# Check existance of multiple options
has <- hasOption(local, c("graphics/cex", "graphics/pch"))
print(has)
graphics/cex graphics/pch 
        TRUE        FALSE 
# Get a subtree of options
graphics <- getOption(local, "graphics")
print(graphics)
$cex
[1] 3
# Get the complete tree of options
all <- getOption(local)
print(all)
$graphics
$graphics$cex
[1] 3

[Package R.utils version 2.11.0 Index]