View source: R/add-missing-column.R
add_missing_column | R Documentation |
This is a convenient way to add one more columns (if not already present) to an existing data frame. It is useful to ensure that all required columns are present in a data frame.
add_missing_column(
.data,
...,
.before = NULL,
.after = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")
)
.data |
Data frame to append to. |
... |
< |
.before , .after |
One-based column index or column name where to add the new columns, default: after last column. |
.name_repair |
Treatment of problematic column names:
This argument is passed on as |
It is wrapper on tibble::add_column()
that doesn't error if the column
is already present.
The original data frame with missing columns added if not already present.
tibble::add_column()
data <- tibble::tibble(x = 1:3, y = 3:1)
tibble::add_column(data, z = -1:1, w = 0)
add_missing_column(data, z = -1:1, .before = "y")
# add_column errors if already present
try(tibble::add_column(data, x = 4:6))
# add_missing_column silently ignores
add_missing_column(data, x = 4:6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.