Skip to content

as.data.table.data.frame keep.rownames & key #4468

Closed
@MichaelChirico

Description

@MichaelChirico

This works fine:

as.data.table(mtcars, keep.rownames = TRUE, key = 'rn')

But it's a bit arcane to know that rn is going to be the rownames' name. More readable might be:

as.data.table(mtcars, keep.rownames = 'model', key = 'model'

But that's an error:

Error in setkeyv(ans, key) : some columns are not in the data.table: model

Haven't looked yet but it must be setkeyv is applied before the setnames.

Note that this approach already works for setDT:

setDT(DT, keep.rownames = 'model', key = 'model')

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions