# Minimal reproducible example
The following R code:
library(data.table)
df <- data.frame(c1 = c(1, 2, 3), c2 = c("a", "b", "c"))
rownames(df) <- as.integer(c(10, 20, 30)) # class(attributes(df)$row.names)
fwrite(df, "out_fwrite", quote = F, row.names = T, sep = "\t")
write.table(df, "out_wt", quote = F, row.names = T, sep = "\t") # added for comparison
generates two output files, whose content is shown below:
out_fwrite
out_wt
c1 c2
10 1 a
20 2 b
30 3 c
I noticed fwrite is converting the actual rownames (i.e. 10, 20, 30) to 1, 2, 3 without warning. This does not happen when rownames(df) <- as.numeric(c(10, 20, 30)) or rownames(df) <- as.character(c(10, 20, 30)). This is also different from the behaviour of write.table.
# Output of sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Scientific Linux 7.2 (Nitrogen)
Matrix products: default
BLAS: /nfs/users2/rg/dgarrido/R/R-4.0.3/lib64/R/lib/libRblas.so
LAPACK: /nfs/users2/rg/dgarrido/R/R-4.0.3/lib64/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] data.table_1.13.6 optparse_1.6.6
loaded via a namespace (and not attached):
[1] compiler_4.0.3 tools_4.0.3 getopt_1.20.3
#Minimal reproducible exampleThe following R code:
generates two output files, whose content is shown below:
out_fwriteout_wtI noticed
fwriteis converting the actual rownames (i.e. 10, 20, 30) to 1, 2, 3 without warning. This does not happen whenrownames(df) <- as.numeric(c(10, 20, 30))orrownames(df) <- as.character(c(10, 20, 30)). This is also different from the behaviour ofwrite.table.#Output of sessionInfo()