unlist
is generic: you can write methods to handle
specific classes of objects, see InternalMethods,
and note, e.g., relist
with the unlist
method
for relistable
objects.
If recursive = FALSE
, the function will not recurse beyond the
first level items in x
.
Factors are treated specially. If all non-list elements of x
are factor
(or ordered factor) objects then the result
will be a factor with
levels the union of the level sets of the elements, in the order the
levels occur in the level sets of the elements (which means that if
all the elements have the same level set, that is the level set of the
result).
x
can be an atomic vector, but then unlist
does nothing useful,
not even drop names.
By default, unlist
tries to retain the naming
information present in x
. If use.names = FALSE
all
naming information is dropped.
Where possible the list elements are coerced to a common mode during
the unlisting, and so the result often ends up as a character
vector. Vectors will be coerced to the highest type of the components
in the hierarchy NULL < raw < logical < integer < double < complex < character
< list < expression: pairlists are treated as lists.
A list is a (generic) vector, and the simplified vector might still be
a list (and might be unchanged). Non-vector elements of the list
(for example language elements such as names, formulas and calls)
are not coerced, and so a list containing one or more of these remains a
list. (The effect of unlisting an lm
fit is a list which
has individual residuals as components.)
Note that unlist(x)
now returns x
unchanged also for
non-vector x
, instead of signalling an error in that case.