Skip to content

Commit

Permalink
Better fix fread's check.names using make.names, #1027.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Dec 17, 2015
1 parent 2c02b25 commit 330dee6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
} else {
setattr(ans, "class", "data.frame")
}
# #1027, make.unique -> make.names as spotted by @DavidArenberg
if (isTRUE(as.logical(check.names))) {
setattr(ans, 'names', make.unique(names(ans)))
setattr(ans, 'names', make.names(names(ans), unique=TRUE))
}
as_factor <- function(x) {
lev = forderv(x, retGrp = TRUE, na.last = NA)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@

6. `dim.data.table` is now implemented in C. Thanks to Andrey Riabushenko.

7. Better fix to `fread`'s `check.names` argument using `make.names()`, [#1027](https://github.com/Rdatatable/data.table/issues/1027). Thanks to @DavidArenberg for spotting the issue with the previous fix using `make.unique()`.

### Changes in v1.9.6 (on CRAN 19 Sep 2015)

#### NEW FEATURES
Expand Down
9 changes: 5 additions & 4 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -6490,11 +6490,12 @@ text = "x,y\n1,a\n2,a\n3,b\n4,b\n5,a\n"
test(1527.3, dt[, y := factor(y)], fread(text, stringsAsFactors=TRUE))

# #1027, check.names argument to fread
nm1 = names(data.table(a=1:2, a=3:4))
nm1 = names(fread("a,a\n1,2\n3,4", check.names=FALSE))
nm2 = names(fread("a,a\n1,2\n3,4", check.names=TRUE))
nm3 = names(fread("a,a\n1,2\n3,4", check.names=FALSE))
test(1528.1, make.unique(nm1), nm2)
test(1528.2, nm1, nm3)
nm3 = names(fread("a b,a b\n1,2\n3,4", check.names=TRUE))
test(1528.1, c("a", "a"), nm1)
test(1528.2, c("a", "a.1"), nm2)
test(1528.3, c("a.b", "a.b.1"), nm3)

# add tests for between
x = sample(10, 20, TRUE)
Expand Down

0 comments on commit 330dee6

Please sign in to comment.