Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@

20. `c`, `seq` and `mean` of `ITime` objects now retain the `ITime` class via new `ITime` methods, [#3628](https://github.com/Rdatatable/data.table/issues/3628). Thanks @UweBlock for reporting. The `cut` and `split` methods for `ITime` have been removed since the default methods work, [#3630](https://github.com/Rdatatable/data.table/pull/3630).

20. `as.data.table.array` now handles the case when some of the array's dimension names are `NULL`, [#3636](https://github.com/Rdatatable/data.table/issues/3636).

#### NOTES

1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below.
Expand Down
9 changes: 7 additions & 2 deletions R/as.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ as.data.table.array = function(x, keep.rownames=FALSE, key=NULL, sorted=TRUE, va
if (!missing(sorted) && !is.null(key))
stop("Please provide either 'key' or 'sorted', but not both.")


dnx = dimnames(x)
# NULL dimnames will create integer keys, not character as in table method
val = rev(if (is.null(dnx)) lapply(dx, seq.int) else dnx)
val = if (is.null(dnx)) {
lapply(dx, seq.int)
} else if (any(nulldnx<-sapply(dnx, is.null))) {
dnx[nulldnx] = lapply(dx[nulldnx], seq.int) #3636
dnx
} else dnx
val = rev(val)
if (is.null(names(val)) || all(!nzchar(names(val))))
setattr(val, 'names', paste0("V", rev(seq_along(val))))
if (value.name %chin% names(val))
Expand Down
10 changes: 10 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -14982,6 +14982,16 @@ test(2055.1, seq(from = as.ITime('00:00:00'), to = as.ITime('00:00:05'), by = 5L
test(2055.2, c(as.ITime(0L), as.ITime(1L)), as.ITime(c(0L, 1L)))
test(2055.3, mean(as.ITime(c(0L, 0L))), as.ITime(0L))

# as.data.table.array some of dimnames are NULL, #3636
a = array(1:8, dim=c(2L,2L,2L), dimnames=list(NULL, NULL, as.character(1:2)))
ans = data.table(V1=c(1L,1L,1L,1L,2L,2L,2L,2L),
V2=c(1L,1L,2L,2L,1L,1L,2L,2L),
V3=c("1","2","1","2","1","2","1","2"),
value=c(1L,5L,3L,7L,2L,6L,4L,8L),
key=c("V1","V2","V3"))
test(2056, as.data.table(a), ans)


###################################
# Add new tests above this line #
###################################
Expand Down