Skip to content

[R-Forge #5016] [fread] 'stringsAsFactors = TRUE' has no effect #501

@arunsrinivasan

Description

@arunsrinivasan

Submitted by: Artem Klevtsov; Assigned to: Nobody; R-Forge link

fread's argument stringsAsFactors has no effect when set to TRUE.

file <- tempfile()
DF <- data.frame(A = 1:10, B = LETTERS[1:10])
sapply(DF, class)
#         A         B 
# "integer"  "factor" 
write.table(DF, file, sep = ";", row.names = FALSE)

# fread's stringsAsFactors has no effect
DT <- fread(file, sep = ";", stringsAsFactors = TRUE)
sapply(DT, class)
#           A           B 
#   "integer" "character" 

Here's the same file read using read.csv():

DF2 <- read.csv(file, sep = ";", stringsAsFactors = TRUE)
sapply(DF2, class)
#         A         B 
# "integer"  "factor" 

DF3 <- read.csv(file, sep = ";", stringsAsFactors = FALSE)
sapply(DF3, class)
#           A           B 
#  "integer" "character" 
unlink(file)

Here's the sessionInfo() output:

sessionInfo()
# R version 3.0.2 (2013-09-25)
# Platform: x86_64-unknown-linux-gnu (64-bit)
# 
# locale:
#  [1] LC_CTYPE=ru_RU.UTF-8       LC_NUMERIC=C               LC_TIME=ru_RU.UTF-8       
#  [4] LC_COLLATE=C               LC_MONETARY=ru_RU.UTF-8    LC_MESSAGES=ru_RU.UTF-8   
#  [7] LC_PAPER=ru_RU.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
# [10] LC_TELEPHONE=C             LC_MEASUREMENT=ru_RU.UTF-8 LC_IDENTIFICATION=C       

# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
# [1] data.table_1.8.11
# 
# loaded via a namespace (and not attached):
# [1] plyr_1.8       reshape2_1.2.2 stringr_0.6.2  tools_3.0.2 

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions