Description Usage Arguments Value See Also Examples
Create some kind of listing, used, e.g., in (error) messages or warnings. Alternatively, make an object ‘flat’, such as by creating a non-nested list from a list, or expand it after splitting certain components.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ## S4 method for signature 'ANY'
flatten(object, ...)
## S4 method for signature 'list'
flatten(object, use.names = TRUE, ...)
## S4 method for signature 'ANY'
listing(x, ...)
## S4 method for signature 'character'
listing(x, header = NULL, footer = NULL,
prepend = FALSE, style = "list", collapse = if (style == "sentence")
""
else
"\n", force.numbers = FALSE,
last.sep = c("and", "both", "comma", "or", "two"), hf.collapse = collapse,
...)
## S4 method for signature 'factor'
listing(x, ...)
## S4 method for signature 'list'
listing(x, ...)
## S4 method for signature 'numeric'
listing(x, ...)
## S4 method for signature 'character'
unnest(object, sep, fixed = TRUE, ...,
stringsAsFactors = FALSE)
## S4 method for signature 'data.frame'
unnest(object, sep, col = names(object),
fixed = TRUE, ..., stringsAsFactors = FALSE)
## S4 method for signature 'list'
unnest(object, ..., stringsAsFactors = FALSE)
|
object |
Usually a list. The default method just
returns |
use.names |
Logical scalar passed to |
x |
For the default method, an object convertible
via |
header |
|
footer |
|
prepend |
Logical, numeric or character scalar. The two main uses are:
|
style |
Character scalar. The main options are:
Note that names and values of |
collapse |
Character scalar used to join the
resulting vector elements. It is by default also applied
for joining |
force.numbers |
Logical scalar. Always use numbers instead of the ‘names’ attribute? |
last.sep |
Character scalar indicating what should
be used as last separator if |
hf.collapse |
Character scalar or empty. If distinct
from |
... |
Optional other arguments passed to
|
sep |
Character scalar passed as |
col |
Character vector with the names of the columns
to be passed to |
fixed |
Logical scalar passed to |
stringsAsFactors |
Logical scalar passed to
|
Character scalar in the case of listing
, data
frame in the case of unnest
.
base::message base::warning base::stop base::formatDL
Other coding-functions: L
,
LL
, assert
,
case
, check
, collect
,
contains
, map_names
,
map_values
, must
,
set
, sql
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | ## listing()
# default style
x <- structure(letters[1:5], names = LETTERS[1:5])
(y <- listing(x, "Five letters:", "...end here", 1))
stopifnot(length(y) == 1, y ==
"Five letters:\n A: a\n B: b\n C: c\n D: d\n E: e\n...end here")
# 'sentence' style
(y <- listing(letters[1:3], style = "sentence", last.sep = "both"))
stopifnot(y == "a, b, and c", length(y) == 1)
(y <- listing(letters[1:3], style = I("sentence"), last.sep = "both"))
stopifnot(y == "1, 2, and 3", length(y) == 1)
(y <- listing(letters[1:3], style = "sentence", prepend = TRUE))
stopifnot(y == "1: a, 2: b and 3: c", length(y) == 1)
(y <- listing(letters[1:3], style = I("sentence"), prepend = TRUE))
stopifnot(y == "a: 1, b: 2 and c: 3", length(y) == 1)
(y <- listing(letters[1:3], style = "sentence", prepend = "%s=>%s"))
stopifnot(y == "1=>a, 2=>b and 3=>c", length(y) == 1)
(y <- listing(letters[1:3], style = "sentence", last.sep = "two"))
stopifnot(y == "a, b, or c", length(y) == 1)
# with explicit sprintf template
(y <- listing(x, style = "%s, %s", collapse = "; ", prepend = "!"))
stopifnot(y == "!A, a; !B, b; !C, c; !D, d; !E, e", length(y) == 1)
(y <- listing(x, style = I("%s, %s"), collapse = "; ", prepend = "!"))
stopifnot(y == "!a, A; !b, B; !c, C; !d, D; !e, E", length(y) == 1)
# create m4 macro definitions
(y <- listing(x, style = "m4"))
stopifnot(grepl("^(define\\([^)]+\\)dnl\n?)+$", y), length(y) == 1)
# other 'x' arguments
stopifnot(listing(x) == listing(as.list(x)))
old.opt <- options(digits = 3)
stopifnot(listing(pi) == "1: 3.14") # controlled by getOption("digits")
options(old.opt)
## flatten()
x <- list(a = list(b = 1:5, c = letters[1:5]), d = LETTERS[1:3],
e = list(pi))
(y <- flatten(x)) # sublists removed, non-list elements kept
stopifnot(is.list(y), length(y) == 4, !sapply(y, is.list))
# atomic objects are not modified by default
stopifnot(identical(letters, flatten(letters)))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.