If you examine the code for these two functions, you will get some clues.
dplyr::mutate
function (.data, ...)
{
UseMethod("mutate")
}
<environment: namespace:dplyr>
tibble::add_column
function (.data, ..., .before = NULL, .after = NULL)
{
df <- tibble(...)
if (ncol(df) == 0L) {
return(.data)
}
if (nrow(df) != nrow(.data)) {
if (nrow(df) == 1) {
df <- df[rep(1L, nrow(.data)), ]
}
else {
stopc("`.data` must have ", nrow(.data), pluralise_n(" row(s)",
nrow(.data)), ", not ", nrow(df))
}
}
extra_vars <- intersect(names(df), names(.data))
if (length(extra_vars) > 0) {
stopc(pluralise_msg("Column(s) ", extra_vars), pluralise(" already exist[s]",
extra_vars))
}
pos <- pos_from_before_after_names(.before, .after, colnames(.data))
end_pos <- ncol(.data) + seq_len(ncol(df))
indexes_before <- rlang::seq2(1L, pos)
indexes_after <- rlang::seq2(pos + 1L, ncol(.data))
indexes <- c(indexes_before, end_pos, indexes_after)
.data[end_pos] <- df
.data[indexes]
}
<environment: namespace:tibble>
Firstly, you will note that they are from two different packages, albeit both part of the tidyverse.
Second, you will see that mutate
uses a specified method whereas add_column
is more of a convenience function written in base r with some rlang magic.
I'm not sure of the roadmap for either package, however, I'm sure you could propose an enhancement if there is not already one raised or fork the project and supply a pull request. It would be a useful addition.
Update
This has been raised in tidyverse/dplyr already and seems to be in the development pipeline, though not yet scheduled.