Unnest spec is a nested list with the same structure as the
nested json. It specifies how the deeply nested lists ought to be
unnested. spec()
is a handy constructor for spec lists. s()
is a
shorthand alias for spec()
.
Usage
spec(
selector = NULL,
...,
as = NULL,
children = NULL,
groups = NULL,
include = NULL,
exclude = NULL,
stack = NULL,
process = NULL,
default = NULL
)
s(
selector = NULL,
...,
as = NULL,
children = NULL,
groups = NULL,
include = NULL,
exclude = NULL,
stack = NULL,
process = NULL,
default = NULL
)
Arguments
- selector
A shorthand syntax for an
include
parameter. Can be a list or a character vector.When
selector
is a list or a character vector with length greater than 1, each element is an include parameter at the corresponding level. For examples(c("a", "b"), ...)
is equivalent tos(include = "a", s(include = "b", ...))
When
selector
is a character of length 1 and contains "/" characters it is split with "/" first. For instances(c("a", "b"), ...)
,s("a/b", ...)
ands("a", s("b", ...))
are all equivalent to the canonicals(include = "a", s(include = "b", ...))
. Components consisting entirely of digits are converted to integers. For examples("a/2/b" ...)
is equivalent tos("a", s(2, s("b", ...)))
Multiple
include
fields can be separated with,
. For examples("a/b,c/d")
is equivalent tos("a", s(include = c("b", "c"), s("d", ...)))
- as
name for this field in the extracted data.frame
- children, ...
Unnamed list of children spec.
...
is merged intochildren
.children
is part of the canonical spec.- groups
Named list of specs to be processed in parallel. The return value is a named list of unnested data.frames. The results is the same as when each spec is
unnest
ed separately except thatdedupe
parameter ofunnest()
will work across groups and execution is faster because the nested list is traversed once regardless of the number of groups.- include, exclude
A list, a numeric vector or a character vector specifying components to include or exclude. A list can combine numeric indexes and character elements to extract.
- stack
Whether to stack this node (TRUE) or to spread it (FALSE). When
stack
is a string an index column is created with that name.- process
Extra processing step for this element. Either NULL for no processing (the default), "as_is" to return the entire element in a list column, "paste" to paste elements together into a character column.
- default
Default value to insert if the
include
specification hasn't matched.
Examples
s("a")
#> <unnest.spec>
#> $ include:"a"
s("a//c2")
#> <unnest.spec>
#> $ include :"a"
#> $ children:List of 1
#> ..$ :<unnest.spec>
#> .. ..$ children:List of 1
#> .. .. ..$ :<unnest.spec>
#> .. .. .. ..$ include:"c2"
s("a/2/c2,cid")
#> <unnest.spec>
#> $ include :"a"
#> $ children:List of 1
#> ..$ :<unnest.spec>
#> .. ..$ include :2
#> .. ..$ children:List of 1
#> .. .. ..$ :<unnest.spec>
#> .. .. .. ..$ include:"c2" "cid"