markfairbanks / tidytable

Tidy interface to 'data.table'
https://markfairbanks.github.io/tidytable/
Other
450 stars 32 forks source link

as_tidytable(.keep_rownames = TRUE) doesn't keep row names of matrices #527

Closed bnicenboim closed 2 years ago

bnicenboim commented 2 years ago

It would be good to not have to go through data frame to keep the rownames of a matrix, see below:

library(tidytable)
#> 
#> Attaching package: 'tidytable'
#> The following object is masked from 'package:stats':
#> 
#>     dt
m <- matrix(data = 1:3)
rownames(m) <- c("a","b","c")
m %>% as_tidytable(.keep_rownames = "id")
#> # A tidytable: 3 × 1
#>      V1
#>   <int>
#> 1     1
#> 2     2
#> 3     3
m %>% as.data.frame() %>% as_tidytable(.keep_rownames = "id")
#> # A tidytable: 3 × 2
#>   id       V1
#>   <chr> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         3

Created on 2022-07-10 by the reprex package (v2.0.1)

markfairbanks commented 2 years ago

All set - thanks for catching this.

pacman::p_load(tidytable)

m <- matrix(data = 1:3)
rownames(m) <- c("a","b","c")
m %>% as_tidytable(.keep_rownames = "id")
#> # A tidytable: 3 × 2
#>   id       V1
#>   <chr> <int>
#> 1 a         1
#> 2 b         2
#> 3 c         3