| example {base} | R Documentation |
Run an Examples Section from the Online Help
Description
Run all the R code from the Examples part of R's online help
topic topic with two possible exceptions, dontrun and
testonly, see Details below.
Usage
example(topic, package = .packages(), lib.loc = NULL,
local = FALSE, echo = TRUE, verbose = getOption("verbose"),
prompt.echo = paste(abbreviate(topic, 6),"> ", sep=""))
Arguments
topic |
name or string constant: the online |
package |
a character vector with package names. By default, all packages in the search path are used. |
lib.loc |
a character vector of directory names of R libraries,
or |
local |
logical: if |
echo |
logical; if |
verbose |
logical; if |
prompt.echo |
character; gives the prompt to be used if
|
Details
If lib.loc is not specified, the packages are searched for
amongst those already loaded, then in the specified libraries.
If lib.loc is specified, they are searched for only
in the specified libraries, even if they are already loaded from
another library.
An attempt is made to load the package before running the examples, but this will not replace a package loaded from another location.
If local=TRUE objects are not created in the workspace and so
not available for examination after example completes: on the
other hand they cannot clobber objects of the same name in the
workspace.
As detailed in the manual Writing R Extensions, the author of the help page can markup parts of the examples for two exception rules
dontrunencloses code that should not be run.
testonlyencloses code that is invisible on help pages, but will be run both by the package checking tools, and the
example()function.
Value
(the value of the last evaluated expression).
Note
The examples can be many small files. On some file systems it is desirable to save space, and the files in the ‘R-ex’ directory of an installed package can be zipped up as a zip archive ‘Rex.zip’.
Author(s)
Martin Maechler and others
See Also
demo
Examples
example(InsectSprays)
## force use of the standard package eda:
example("smooth", package="eda", lib.loc=.Library)