Turn (data frames with) tf-objects / list columns into "long" tables.
Source: R/tidyr.R
tf_unnest.RdSimilar in spirit to tidyr::unnest(), the reverse of tf_nest().
The tf-method simply turns a single tfd or tfb vector into a "long" tibble().
Usage
tf_unnest(data, cols, arg, interpolate = TRUE, ...)
# S3 method for tf
tf_unnest(data, cols, arg, interpolate = TRUE, ...)
# S3 method for data.frame
tf_unnest(
data,
cols,
arg,
interpolate = TRUE,
keep_empty = FALSE,
ptype = NULL,
names_sep = "_",
names_repair = "check_unique",
...
)Arguments
- data
a data.frame or a
tf-object- cols
<
tidy-select> List-columns to unnest.When selecting multiple columns, values from the same row will be recycled to their common size.
- arg
optional values for the
argargument oftf_evaluate()- interpolate
return function values for
arg-values not on original grid? Defaults toTRUE.- ...
not used currently
- keep_empty
By default, you get one row of output for each element of the list that you are unchopping/unnesting. This means that if there's a size-0 element (like
NULLor an empty data frame or vector), then that entire row will be dropped from the output. If you want to preserve all rows, usekeep_empty = TRUEto replace size-0 elements with a single row of missing values.- ptype
Optionally, a named list of column name-prototype pairs to coerce
colsto, overriding the default that will be guessed from combining the individual values. Alternatively, a single empty ptype can be supplied, which will be applied to allcols.- names_sep
If
NULL, the default, the outer names will come from the inner names. If a string, the outer names will be formed by pasting together the outer and the inner column names, separated bynames_sep.- names_repair
Used to check that output data frame has valid names. Must be one of the following options:
"minimal": no name repair or checks, beyond basic existence,"unique": make sure names are unique and not empty,"check_unique": (the default), no name repair, but check they are unique,"universal": make the names unique and syntactica function: apply custom name repair.
tidyr_legacy: use the name repair from tidyr 0.8.
a formula: a purrr-style anonymous function (see
rlang::as_function())
See
vctrs::vec_as_names()for more details on these terms and the strategies used to enforce them.
Details
Caution -- uses slightly different defaults for names of unnested columns than
tidyr::unnest().For
data.frames, make sure to have an ID column in your data before unnesting! If it does not include an ID column with a unique identifier for each row, you will not be able to match arg-value pairs to the different functions after unnesting.
See also
tf_evaluate.data.frame()
Other tidyfun data wrangling functions:
tf_evaluate.data.frame(),
tf_gather(),
tf_nest(),
tf_spread()