161161 i <- vectbl_as_row_location2(i , fast_nrow(x ), i_arg , assign = TRUE )
162162 }
163163
164- value <- list (value )
165-
166164 if (is.object(j )) {
167165 j <- vectbl_as_col_subscript2(j , j_arg , assign = TRUE )
168166 }
@@ -174,10 +172,11 @@ NULL
174172 }
175173 }
176174
177- j <- vectbl_as_new_col_index(j , x , value , j_arg , value_arg )
175+ j <- vectbl_as_new_col_index(j , x , j_arg )
178176
179177 # New columns are added to the end, provide index to avoid matching column
180178 # names again
179+ value <- list (value )
181180 names(value ) <- names(j )
182181
183182 tbl_subassign(x , i , j , value , i_arg = i_arg , j_arg = j_arg , value_arg = value_arg )
@@ -418,7 +417,7 @@ tbl_subassign <- function(x, i, j, value, i_arg, j_arg, value_arg) {
418417 if (is.null(j )) {
419418 j <- seq_along(x )
420419 } else if (! is.null(j_arg )) {
421- j <- vectbl_as_new_col_index(j , x , value , j_arg , value_arg )
420+ j <- vectbl_as_new_col_index(j , x , j_arg , names2( value ) , value_arg )
422421 }
423422
424423 value <- vectbl_recycle_rhs(value , fast_nrow(x ), length(j ), i_arg = NULL , value_arg )
@@ -441,7 +440,7 @@ tbl_subassign <- function(x, i, j, value, i_arg, j_arg, value_arg) {
441440 # (Invariant: x[[j]] is equivalent to x[[vec_as_location(j)]],
442441 # allowed by corollary that only existing columns can be updated)
443442 if (! is.null(j_arg )) {
444- j <- vectbl_as_new_col_index(j , x , value , j_arg , value_arg )
443+ j <- vectbl_as_new_col_index(j , x , j_arg , names2( value ) , value_arg )
445444 }
446445 new <- which(j > length(x ))
447446 value <- vectbl_recycle_rhs(value , length(i ), length(j ), i_arg , value_arg )
@@ -487,7 +486,7 @@ vectbl_as_new_row_index <- function(i, x, i_arg) {
487486 }
488487}
489488
490- vectbl_as_new_col_index <- function (j , x , value , j_arg , value_arg ) {
489+ vectbl_as_new_col_index <- function (j , x , j_arg , names = " " , value_arg = NULL ) {
491490 # Creates a named index vector
492491 # Values: index
493492 # Name: column name (for new columns)
@@ -508,14 +507,18 @@ vectbl_as_new_col_index <- function(j, x, value, j_arg, value_arg) {
508507 cnd_signal(error_assign_columns_non_na_only())
509508 }
510509
511- j <- numtbl_as_col_location_assign(j , ncol (x ), j_arg = j_arg )
510+ j <- numtbl_as_col_location_assign(j , length (x ), j_arg = j_arg )
512511
513- new <- which(j > ncol (x ))
512+ new <- which(j > length (x ))
514513 j_new <- j [new ]
515514
516- # FIXME: Recycled names are not repaired
517- # FIXME: Hard-coded name repair
518- names <- vectbl_recycle_rhs_names(names2(value ), length(j ), value_arg )
515+ if (length(names ) != 1L ) {
516+ # Side effect: check compatibility
517+ vec_recycle(names , length(j ), x_arg = as_label(value_arg ))
518+ } else if (length(j ) != 1L ) {
519+ names <- vec_recycle(names , length(j ), x_arg = as_label(value_arg ))
520+ names [new ] <- paste0(names [new ], " ..." , j [new ])
521+ }
519522
520523 if (length(new ) > 0 ) {
521524 j [new ] <- j_new
@@ -753,13 +756,6 @@ vectbl_recycle_rhs <- function(value, nrow, ncol, i_arg, value_arg) {
753756 value
754757}
755758
756- vectbl_recycle_rhs_names <- function (names , n , value_arg ) {
757- if (n == 1L && length(names ) == 1L ) {
758- return (names )
759- }
760- unname(vec_recycle(set_names(names ), n , x_arg = as_label(value_arg )))
761- }
762-
763759# Dedicated functions for faster subsetting
764760set_tibble_class <- function (x , nrow ) {
765761 attr(x , " row.names" ) <- .set_row_names(nrow )
0 commit comments