Skip to content
12 changes: 10 additions & 2 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -1136,9 +1136,17 @@ setMethod("collect",

# Note that "binary" columns behave like complex types.
if (!is.null(PRIMITIVE_TYPES[[colType]]) && colType != "binary") {
vec <- do.call(c, col)
valueIndex <- which(!is.na(col))
if (length(valueIndex) > 0 && valueIndex[1] > 1) {
colTail <- col[-(1 : (valueIndex[1] - 1))]
vec <- do.call(c, colTail)
classVal <- class(vec)
vec <- c(rep(NA, valueIndex[1] - 1), vec)
class(vec) <- classVal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what happened here?
if you want to drop the NA and use the rest to infer the class you can do col[!is.na(col)]

} else {
vec <- do.call(c, col)
}
stopifnot(class(vec) != "list")
class(vec) <- PRIMITIVE_TYPES[[colType]]
df[[colIndex]] <- vec
} else {
df[[colIndex]] <- col
Expand Down