Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
}
if (toupper(tt)!=toupper(i)) {
warning(cmd, " returned '",tt,"' != '",i,"' (not NULL not '' and allowing for case differences). This may not be a problem but please report.")
}
}
if (Sys.localeconv()["decimal_point"] == dec) break
if (verbose) cat("Successfully changed locale but it provides dec='",Sys.localeconv()["decimal_point"],"' not the desired dec", sep="")
}
Expand Down Expand Up @@ -98,7 +98,7 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
setattr(ans, 'names', make.unique(names(ans)))
}
as_factor <- function(x) {
lev = forderv(x, retGrp = TRUE)
lev = forderv(x, retGrp = TRUE, na.last = NA)
# get levels, also take care of all sorted condition
if (length(lev)) lev = x[lev[attributes(lev)$starts]]
else lev = x[attributes(lev)$starts]
Expand All @@ -110,7 +110,7 @@ fread <- function(input="",sep="auto",sep2="auto",nrows=-1L,header="auto",na.str
cols = which(vapply(ans, is.character, TRUE))
if (length(cols)) {
if (verbose) cat("Converting column(s) [", paste(names(ans)[cols], collapse = ", "), "] from 'char' to 'factor'\n", sep = "")
for (j in cols)
for (j in cols)
set(ans, j = j, value = as_factor(.subset2(ans, j)))
}
}
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

13. `fread` reads text input with empty newline but with just spaces properly, for e.g., fread('a,b\n1,2\n '), [#1384](https://github.com/Rdatatable/data.table/issues/1384). Thanks to @ladida771.

14. `fread` with `stringsAsFactors = TRUE` no longer produces factors with NA as a factor level, [#1408](https://github.com/Rdatatable/data.table/pull/1408). Thanks to @DexGroves.

#### NOTES

1. Updated error message on invalid joins to reflect the new `on=` syntax, [#1368](https://github.com/Rdatatable/data.table/issues/1368). Thanks @MichaelChirico.
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7075,6 +7075,14 @@ setattr(attr(X, 'index'), 'x', 5:1) # auto indexed attribute as created from v1.
ans = capture.output(X[, z := 1:5, verbose=TRUE])
test(1576, ans[4], "Dropping index 'x' as it doesn't have '__' at the beginning of index name. It is very likely created using v1.9.4 of data.table.")

# fix for #1408
X = fread("a|b|c|d
this|is|row|1
this|is|row|2
this|NA|NA|3
this|is|row|4", stringsAsFactors = TRUE)
test(201.1, is.na(X[3, b]), TRUE)

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


Expand Down