Skip to content

indices/key2 should return list #1589

@jangorecki

Description

@jangorecki

There can be multiple indices on single data.table, each index can be set on multiple fields.
The most correct representation then is to return list of vectors.
Current behavior:

library(data.table)
dt = data.table(a=1,b=2,c=3,d=4)
setindexv(dt, "a")
setindexv(dt, c("a","b"))
setindexv(dt, c("b","a"))
setindexv(dt, c("d","c","a"))
indices(dt)
#[1] "a"       "a__b"    "b__a"    "d__c__a"

Expected

list("a", c("a","b"), c("b","a"), c("d","c","a"))
#[[1]]
#[1] "a"
#
#[[2]]
#[1] "a" "b"
#
#[[3]]
#[1] "b" "a"
#
#[[4]]
#[1] "d" "c" "a"

There could be an additional argument forcing to return a vector instead of list by collapsing column names.

sapply(list("a", c("a","b"), c("b","a"), c("d","c","a")), paste, collapse=",")
#[1] "a"     "a,b"   "b,a"   "d,c,a"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions