Open
Description
Help says that for as.data.frame()
, x
can be any R object and row.names
can be a character
vector giving the row names for the data frame.
Although tibble
has a valid opinion on rownames
, the output is a data.frame
. So, I believe that the as.data.frame.tbl_df()
method should not ignore row.names
argument and set the attribute like as.data.frame.data.frame()
does.
Obviously, I am not the expert so I am willing to be corrected. Thank You :)
library(tibble)
# as.data.frame.tbl_df() ignores 'row.names'
as.data.frame(tibble(x = 1:2), row.names = letters[1:2])
# x
#1 1
#2 2
# as.data.frame.data.frame() does not ignore 'row.names'
as.data.frame(data.frame(x = 1:2), row.names = letters[1:2])
# x
# a 1
# b 2
sessionInfo()
sessionInfo()
# R version 4.2.1 (2022-06-23 ucrt)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19044)
#
# Matrix products: default
#
# locale:
# [1] LC_COLLATE=English_India.utf8 LC_CTYPE=English_India.utf8
# [3] LC_MONETARY=English_India.utf8 LC_NUMERIC=C
# [5] LC_TIME=English_India.utf8
#
# attached base packages:
# [1] stats graphics grDevices datasets utils methods base
#
# other attached packages:
# [1] tibble_3.1.7
#
# loaded via a namespace (and not attached):
# [1] compiler_4.2.1 magrittr_2.0.3 ellipsis_0.3.2 cli_3.3.0
# [5] pillar_1.7.0 glue_1.6.2 crayon_1.5.1 utf8_1.2.2
# [9] fansi_1.0.3 vctrs_0.4.1 lifecycle_1.0.1 pkgconfig_2.0.3
# [13] rlang_1.0.3