Skip to content

Commit b6cc6ac

Browse files
merge our loop which checks for vector rowname extraction in below
1 parent 92f281f commit b6cc6ac

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

R/as.data.table.R

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,19 @@ as.data.table.list = function(x,
133133
missing.check.names = missing(check.names)
134134
origListNames = if (missing(.named)) names(x) else NULL # as.data.table called directly, not from inside data.table() which provides .named, #3854
135135
empty_atomic = FALSE
136-
137-
#Handle keep.rownames for vectors (mimicking data.frame behavior)
136+
# Handle keep.rownames for vectors (mimicking data.frame behavior)
138137
vector_rownames = NULL
139-
if (!isFALSE(keep.rownames)) {
140-
for (i in seq_len(n)) {
141-
xi = x[[i]]
142-
if (!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)
147-
break
148-
}
149-
}
150-
}
151-
}
138+
check_rownames = !isFALSE(keep.rownames)
152139
for (i in seq_len(n)) {
153140
xi = x[[i]]
154141
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)
147+
}
148+
}
155149
if (!is.null(dim(xi)) && missing.check.names) check.names=TRUE
156150
if ("POSIXlt" %chin% class(xi)) {
157151
warningf("POSIXlt column type detected and converted to POSIXct. We do not recommend use of POSIXlt at all because it uses 40 bytes to store one date.")

0 commit comments

Comments
 (0)