Skip to content

setDT should accept named vectors #1244

@MichaelChirico

Description

@MichaelChirico

Just came across a situation where I want to use a named vector in a way most easily handled by a join, but unfortunately:

join_vector <- c("id1"=1, "id2"=2, "id3"=3)
setDT(join_vector, keep.rownames=T)

Is an error: Argument 'x' to 'setDT' should be a 'list', 'data.frame' or 'data.table'

However, first casting join_vector as a data.frame works:

setDT(data.frame(join_vector), keep.rownames=T)

(though this returns an invisible object, since data.frame(join_vector) isn't assigned to anything).

Is there any reason not to allow setDT to re-class vectors like the above?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions