Rename columns and add defaults values if column not present
Source:R/utils-dataset-converters.R
convert_f_defaults.Rd
convert_f_defaults()
combine the dplyr::rename()
way of
working and with the tibble::add_column()
to add columns
with default values in case they don't exist after renaming data.
Usage
convert_f_defaults(.data, ..., .def_col_val = c(), .use_dots = TRUE)
Arguments
- .data
A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr). See Methods, below, for more details.
- ...
For
rename()
: <tidy-select
> Usenew_name = old_name
to rename selected variables.For
rename_with()
: additional arguments passed onto.fn
.- .def_col_val
Named vector with columns with default values if none exist after rename.
- .use_dots
Should a dot prefix be added to renamed variables? This will allow swapping of columns.
Value
An object of the same type as .data. The output has the following properties:
Rows are not affected.
Column names are changed.
Column order is the same as that of the function call.
Details
The objective of using .use_dots is to be able to swap columns which,
by default, is not allowed by the dplyr::rename()
function.
The same behavior can be replicated by simply using the dplyr::select()
,
however, the select evaluation allows much more flexibility so that
unexpected results could be obtained. Despite this, a future implementation
will consider this form of execution to allow renaming the same
column to multiple ones (i.e. extend dataframe extension).