Skip to content

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

Closed

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 

Activity

  1. nr0cinu commented on Feb 10, 2015

    @nr0cinu

    same here :(

  2. TheVinhLuong102 commented on Apr 6, 2015

    @TheVinhLuong102

    Hi all, I have the same problem

  3. mplatzer commented on Apr 17, 2015

    @mplatzer

    same here

  4. DavidArenburg commented on Apr 17, 2015

    @DavidArenburg
    Member

    Guys you can stop commenting- it is the same for everyone without exceptions.

  5. added this to the v1.9.6 milestone on Jul 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions