Skip to content

Commit

Permalink
stringsAsFactors for data.table() also closes #643.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Feb 9, 2016
1 parent 3dbc493 commit 9edbb3e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ data.table <-function(..., keep.rownames=FALSE, check.names=FALSE, key=NULL, str
&& !any(duplicated(names(value)[names(value) %in% ckey])))
setattr(value, "sorted", ckey)
}
# FR #1446, setfactor is an internal function in fread.R
# FR #643, setfactor is an internal function in fread.R
if (isTRUE(stringsAsFactors)) setfactor(value, which(vapply(value, is.character, TRUE)), FALSE)
alloc.col(value) # returns a NAMED==0 object, unlike data.frame()
}
Expand Down
6 changes: 6 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7383,6 +7383,12 @@ smp = sample(30, size =10)
lgl = dt$id %in% smp
test(1597, dt[lgl, ], dt[id %in% smp])

# FR #643
vv = sample(letters[1:3], 10, TRUE)
test(1599.1, data.table(x=vv, y=1:10, stringsAsFactors=TRUE)$x, factor(vv))
vv = sample(c(letters[1:3], NA), 10, TRUE)
test(1599.2, data.table(x=vv, y=1:10, stringsAsFactors=TRUE)$x, factor(vv))

##########################

# TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.
Expand Down

0 comments on commit 9edbb3e

Please sign in to comment.