Search code examples
rrowdtrow-numbertibble

Drop row numbers in R tibble


How do I drop the row numbers when displaying R tibble through the DT package?

The options = list(rownames = FALSE) argument doesn't seem to work, I also "made up" options = list(rownumbers = FALSE) and that didn't work. I messed around with things like select(2:everything()) but that did not work either. Maybe piping in remove_rownames() at then end will work... it does not, or perhaps as.data.frame() piped at the end... Nope.

library(tidyverse)
library(DT)
datatable(mtcars %>% head() %>% as_tibble(), options = list(rownames = FALSE))

tibble with row numbers


Solution

  • library(tidyverse)
    library(DT)
    datatable(mtcars %>% head() %>% as_tibble, rownames = FALSE)
    

    You just need to rearrange the parenthesis, so that the rownames value is changed for datatable and not for the as_tibble call.

    enter image description here