@@ -139,11 +139,21 @@ as.data.table.list = function(x,
139139 for (i in seq_len(n )) {
140140 xi = x [[i ]]
141141 if (is.null(xi )) next # eachncol already initialized to 0 by integer() above
142- if (check_rownames && is.null(vector_rownames ) && ! is.null(xi ) && is.atomic(xi ) && ! is.null(names(xi )) && is.null(dim(xi ))) {
143- valid_names = names(xi )
144- if (any(nzchar(valid_names ))) {
145- vector_rownames = valid_names
146- x [[i ]] = unname(xi )
142+ if (check_rownames && is.null(vector_rownames )) {
143+ # Check for named vectors
144+ if (is.atomic(xi ) && ! is.null(names(xi )) && is.null(dim(xi ))) {
145+ valid_names = names(xi )
146+ if (any(nzchar(valid_names ))) {
147+ vector_rownames = valid_names
148+ x [[i ]] = unname(xi )
149+ }
150+ }
151+ # Check for data.frames or matrices with explicit rownames
152+ else if (! is.null(dim(xi )) && ! is.null(rownames(xi ))) {
153+ valid_names = rownames(xi )
154+ if (any(nzchar(valid_names ))) {
155+ vector_rownames = valid_names
156+ }
147157 }
148158 }
149159 if (! is.null(dim(xi )) && missing.check.names ) check.names = TRUE
@@ -155,7 +165,7 @@ as.data.table.list = function(x,
155165 if (is.matrix(xi ) && NCOL(xi )< = 1L && is.null(colnames(xi ))) { # 1 column matrix naming #4124
156166 xi = x [[i ]] = c(xi )
157167 } else {
158- xi = x [[i ]] = as.data.table(xi , keep.rownames = keep.rownames ) # we will never allow a matrix to be a column; always unpack the columns
168+ xi = x [[i ]] = as.data.table(xi , keep.rownames = FALSE ) # we will never allow a matrix to be a column; always unpack the columns
159169 }
160170 }
161171 # else avoid dispatching to as.data.table.data.table (which exists and copies)
0 commit comments