unnestList | R Documentation |
Un-nest a nested list into a simple list
unnestList(
x,
addNames = FALSE,
unnamedBase = "x",
parentName = NULL,
sep = ".",
makeNamesFunc = makeNames,
stopClasses = c("dendrogram", "data.frame", "matrix", "package_version", "tbl",
"data.table"),
extraStopClasses = getOption("jam.stopClasses"),
...
)
x |
|
addNames |
|
unnamedBase |
|
sep |
|
makeNamesFunc |
|
stopClasses |
|
extraStopClasses |
|
... |
additional arguments are ignored. |
This function inspects a list, and unlists each entry resulting in a simple list of non-list entries as a result. Sometimes when concatenating lists together, one list gets added as a list-of-lists. This function resolves that problem by providing one flat list.
list
that has been flattened so that it contains
no list
elements. Note that it may contain some list-like
objects such as data.frame
, defined by stopClasses
.
Other jam list functions:
cPasteSU()
,
cPasteS()
,
cPasteUnique()
,
cPasteU()
,
cPaste()
,
heads()
,
jam_rapply()
,
list2df()
,
mergeAllXY()
,
mixedSorts()
,
rbindList()
,
relist_named()
,
rlengths()
,
sclass()
,
sdim()
,
uniques()
L <- list(A=letters[1:10],
B=list(C=LETTERS[3:9], D=letters[4:11]),
E=list(F=list(G=LETTERS[3:9], D=letters[4:11])));
L;
# inspect the data using str()
str(L);
unnestList(L);
# optionally change the delimiter
unnestList(L, sep="|");
# example with nested lists of data.frame objects
df1 <- data.frame(a=1:2, b=letters[3:4]);
DFL <- list(A=df1,
B=list(C=df1, D=df1),
E=list(F=list(G=df1, D=df1)));
str(DFL);
unnestList(DFL);
str(unnestList(DFL));
# packageVersion() returns class "package_version"
# where is.list(packageVersion("base")) is TRUE,
# but it cannot ever be subsetted as a list with x[[1]],
# and thus it breaks this function
identical(is.list(packageVersion("base")), is.list(packageVersion("base"))[[1]])
unnestList(lapply(nameVector(c("base","graphics")), packageVersion))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.