require(data.table) # devel built 2017-10-31dt<- data.table()
attributes(dt)
# $class# [1] "data.table" "data.frame"## $row.names# integer(0)## $names# character(0)## $.internal.selfref# <pointer: 0x0000000000310788>#
setnames(dt, character(0))
# Error in setnames(dt, character(0)) : x has no column names
names(df) <- character(0) would work on a null data.frame. I think this should not error. The reason is that it avoids an unnecessary if (ncol(dt)) before to do setnames(dt, nm) where nm is the vector of names, which would be character(0) if dt had no cols.
Output of sessionInfo()
# R version 3.3.2 (2016-10-31)# Platform: x86_64-w64-mingw32/x64 (64-bit)# Running under: Windows Server >= 2012 x64 (build 9200)## locale:# [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 # [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C # [5] LC_TIME=English_United States.1252 # attached base packages:# [1] stats graphics grDevices utils datasets methods base ## other attached packages:# [1] data.table_1.10.5## loaded via a namespace (and not attached):# [1] tools_3.3.2 yaml_2.1.14
The text was updated successfully, but these errors were encountered:
if (!length(attr(x, "names"))) stop("x has no column names") # because setnames is for user user. Internally, use setattr(x,"names",...)
I don't think I understand the comment? Can't this line just be expunged and that's that? test.data.table() runs fine if I do so & rebuild. So at the very least the purpose of that line is absent from the test suite...
I don't understand the comment and I think that line needn't exist, since the next line ensures that cols of data.table and the input character vector are identical.
names(df) <- character(0)
would work on a null data.frame. I think this should not error. The reason is that it avoids an unnecessaryif (ncol(dt))
before to dosetnames(dt, nm)
wherenm
is the vector of names, which would becharacter(0)
ifdt
had no cols.Output of sessionInfo()
The text was updated successfully, but these errors were encountered: