-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
According to the documentation of data.frame, I() can be used to prevent data.frame from stripping the names of a vector. By contrast, data.table strips the names still but does preserve the "asis" class. Is this difference expected?
library('data.table')
fake = setNames(1:3, c('a','b','c'))
data.frame(v1 = I(fake))[, 'v1']
#> a b c
#> 1 2 3
class(data.frame(v1 = I(fake))[, 'v1'])
#> [1] "AsIs"
data.table(v1 = I(fake))[, v1]
#> [1] 1 2 3
class(data.table(v1 = I(fake))[, v1])
#> [1] "AsIs"
sessionInfo()
#> R version 4.0.2 (2020-06-22)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 18363)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=English_United States.1252
#> [2] LC_CTYPE=English_United States.1252
#> [3] LC_MONETARY=English_United States.1252
#> [4] LC_NUMERIC=C
#> [5] LC_TIME=English_United States.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] data.table_1.13.0
#>
#> loaded via a namespace (and not attached):
#> [1] compiler_4.0.2 magrittr_1.5 tools_4.0.2 htmltools_0.5.0
#> [5] yaml_2.2.1 stringi_1.4.6 rmarkdown_2.3 highr_0.8
#> [9] knitr_1.29 stringr_1.4.0 xfun_0.16 digest_0.6.25
#> [13] rlang_0.4.7 evaluate_0.14Created on 2020-11-02 by the reprex package (v0.3.0)
Metadata
Metadata
Assignees
Labels
No labels