The error is coming from the $<-.data.frame function
> `$<-.data.frame`
function (x, name, value)
{
cl <- oldClass(x)
class(x) <- NULL
nrows <- .row_names_info(x, 2L)
if (!is.null(value)) {
N <- NROW(value)
if (N > nrows)
stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
"replacement has %d rows, data has %d"), N, nrows),
domain = NA)
...
i.e. the condition for N > nrows is satisfied
> NROW(c(7, 8))
[1] 2
> .row_names_info(df, 2L)
[1] 3
which is confirmed by traceback() on the error
> traceback()
3: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
"replacement has %d rows, data has %d"), N, nrows), domain = NA)
2: `$<-.data.frame`(`*tmp*`, z, value = c(7, 8))
1: `$<-`(`*tmp*`, z, value = c(7, 8))