
Last chance! 50% off unlimited learning
Sale ends in
Object
~~|
~~+--
Options
~~~~~~~|
~~~~~~~+--
Settings
Directly known subclasses:
public static class Settings
extends Options
Class for applicational settings.Settings(basename=NULL, ...)
character
string of the basename of the settings file.findSettings
Searches for the settings file in one or several directories.
getLoadedPathname
Gets the pathname of the settings file loaded.
isModified
Checks if settings has been modified compared to whats on file.
loadAnywhere
Loads settings from file.
promptAndSave
Prompt user to save modified settings.
saveAnywhere
Saves settings to file.
}
Methods inherited from Options:
as.character, as.list, equals, getLeaves, getOption, hasOption, names, nbrOfOptions, setOption, str
Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstantiationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, registerFinalizer, save.First.lib()
function for loading settings
with package. It also (almost) assures that the package is detached
when R finishes. See onSessionExit
() why it is not guaranteed!
The almost generic .Last.lib()
function, which will prompt
user to save settings, is called when a package is detached.
It is custom to put these functions in a file named zzz.R
.
.First.lib():
.First.lib <- function(libname, pkgname) {
# Write a welcome message when package is loaded
pkg <- Package(pkgname);
assign(pkgname, pkg, pos=getPosition(pkg));
# Read settings file ".# Load settings from file, or create default settings
basename <- "some.settings"
settings <- Settings$loadAnywhere(basename)
if (is.null(settings))
settings <- Settings(basename)
# Set default options, if missing.
setOption(settings, "graphics/verbose", TRUE, overwrite=FALSE)
setOption(settings, "io/verbose", Verbose(threshold=-1), overwrite=FALSE)
# Save and reload settings
path <- tempdir()
saveAnywhere(settings, path=path)
settings2 <- Settings$loadAnywhere(basename, paths=path)
# Clean up
file.remove(getLoadedPathname(settings2))
# Assert correctness
stopifnot(equals(settings, settings2))
Run the code above in your browser using DataLab