This command will display and/or execute small snippets of R code from the book Foundations and Applications of Statistics: An Introduction Using R.
Arguments
- name
name of snippet
- eval
a logical. An alias for `execute`.
- execute
a logical. If
TRUE
, snippet code is executed. (The code and the results of the execution will be visible ifecho
isTRUE
.)- view
a logical. If
TRUE
, snippet code is displayed 'as is'.- echo
a logical. If
TRUE
, show the R input when executing.- ask
a logical (or "default") indicating if
devAskNewPage(ask=TRUE)
should be called before graphical output happens from the snippet code. The value "default" (the factory-fresh default) means to ask ifecho == TRUE
and the graphics device appears to be interactive. This parameter applies both to any currently opened device and to any devices opened by the demo code. If this is evaluated toTRUE
and the session is interactive, the user is asked to press RETURN to start.- verbose
a logical. If
TRUE
, additional diagnostics are printed.- lib.loc
character vector of directory names of R libraries, or NULL. The default value of NULL corresponds to all libraries currently known.
- character.only
logical. If
TRUE
, usename
as character string.- regex
ignored. Retained for backwards compatibility.
- max.files
an integer limiting the number of files retrieved.
Details
snippet
works much like demo
, but the interface is
simplified. Partial matching is used to select snippets, so any unique
prefix is sufficient to specify a snippet. Sequenced snippets (identified by
trailing 2-digit numbers) will be executed in sequence if a unique prefix to
the non-numeric portion is given. To run just one of a sequence of snippets,
provide the full snippet name. See the examples.
Examples
snippet("normal01")
#> Error in snippet("normal01"): No snippet matching 'normal01'
# prefix works
snippet("normal")
#> Error in snippet("normal"): No snippet matching 'normal'
# this prefix is ambiguous
snippet("norm")
#> Multiple matches found for `norm':
#> normal, normal-grid, normal-loglik, normal-mle
# sequence of "histogram" snippets
snippet("hist", eval = FALSE, echo = TRUE, view = FALSE)
#> Error in snippet("hist", eval = FALSE, echo = TRUE, view = FALSE): No snippet matching 'hist'
# just one of the "histogram" snippets
snippet("histogram04", eval = FALSE, echo = TRUE, view = FALSE)
#> Error in snippet("histogram04", eval = FALSE, echo = TRUE, view = FALSE): No snippet matching 'histogram04'
# Prefix too short, but a helpful message is displayed
snippet("h", eval = FALSE, echo = TRUE, view = FALSE)
#> Multiple matches found for `h':
#> hatvalues, heavy-tails, helium-footballs, help, histogram, hugo