View source: R/utils-dataset-converters.R
convert_f_defaults | R Documentation |
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.
convert_f_defaults(.data, ..., .def_col_val = c(), .use_dots = TRUE)
.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 For |
.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. |
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).
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.
df <- tibble::tibble(x = 1, y = 2, z = 3)
# Rename columns
df <- tibble::tibble(x = 1, y = 2)
convert_f_defaults(
.data = df,
new_x = x,
new_y = y,
new_z = NULL,
.def_col_val = c(new_z = 3)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.