Skip to content
Closed
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

3. Vignettes are now built using `litedown` instead of `knitr`, [#6394](https://github.com/Rdatatable/data.table/issues/6394). Thanks @jangorecki for the suggestion and @ben-schwen and @aitap for the implementation.

4. `fread` now prints a message by default when creating one or more integer64 columns, warning that this type sometimes give unexpected results like in case of as.matrix(). The message can be suppressed with the new argument `no.integer64.message=TRUE`. To avoid integer64 columns, we can use options(datatable.integer64='numeric'). Thanks to @stefanfritsch, @mattdowle for the suggestion. [#3611](https://github.com/Rdatatable/data.table/issues/3611)

### BUG FIXES

1. `fread()` with `skip=0` and `(header=TRUE|FALSE)` no longer skips the first row when it has fewer fields than subsequent rows, [#7463](https://github.com/Rdatatable/data.table/issues/7463). Thanks @emayerhofer for the report and @ben-schwen for the fix.
Expand Down
16 changes: 15 additions & 1 deletion R/fread.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ showProgress=getOption("datatable.showProgress",interactive()), data.table=getOp
nThread=getDTthreads(verbose), logical01=getOption("datatable.logical01",FALSE),
logicalYN=getOption("datatable.logicalYN", FALSE),
keepLeadingZeros=getOption("datatable.keepLeadingZeros",FALSE),
yaml=FALSE, tmpdir=tempdir(), tz="UTC")
yaml=FALSE, tmpdir=tempdir(), tz="UTC", no.integer64.message=FALSE
)
{
if (missing(input)+is.null(file)+is.null(text)+is.null(cmd) < 3L) stopf("Used more than one of the arguments input=, file=, text= and cmd=.")
input_has_vars = length(all.vars(substitute(input)))>0L # see news for v1.11.6
Expand Down Expand Up @@ -261,13 +262,26 @@ yaml=FALSE, tmpdir=tempdir(), tz="UTC")
if (identical(tt,"") || is_utc(tt)) # empty TZ env variable ("") means UTC in C library, unlike R; _unset_ TZ means local
tz="UTC"
}

ans = .Call(CfreadR,input,identical(input,file),sep,dec,quote,header,nrows,skip,na.strings,strip.white,blank.lines.skip,comment.char,
fill,showProgress,nThread,verbose,warnings2errors,logical01,logicalYN,select,drop,colClasses,integer64,encoding,keepLeadingZeros,tz=="UTC")
if (!length(ans)) return(null.data.table()) # test 1743.308 drops all columns
nr = length(ans[[1L]])
require_bit64_if_needed(ans)
setattr(ans,"row.names",.set_row_names(nr))

# integer64 message on create - instead of warning
if (!isTRUE(no.integer64.message) &&
identical(integer64, "integer64") &&
any(vapply(ans, inherits, logical(1L), what = "integer64"))) {
message(
"fread: Creating one or more integer64 columns.
See ?fread and ?bit64::integer64.
To suppress this message, use no.integer64.message=TRUE.
To avoid integer64 columns, use options(datatable.integer64='numeric')."
)
}

if (isTRUE(data.table)) {
setattr(ans, "class", c("data.table", "data.frame"))
setalloccol(ans)
Expand Down
9 changes: 9 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21978,3 +21978,12 @@ local({
test(2357.1, fread(f), DT)
test(2357.2, fread(paste0("file://", f)), DT)
})
#3611 fread integer64 message
test(2358.1,
suppressMessages(fread("a\n1\n2\n", colClasses = "integer64")),
data.table(a = as.integer64(c(1,2)))
)
test(2358.2,
suppressMessages(fread("a\n1\n2\n", colClasses = "integer64", no.integer64.message = TRUE)),
data.table(a = as.integer64(c(1,2)))
)
3 changes: 2 additions & 1 deletion man/fread.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ nThread=getDTthreads(verbose),
logical01=getOption("datatable.logical01", FALSE),
logicalYN=getOption("datatable.logicalYN", FALSE),
keepLeadingZeros = getOption("datatable.keepLeadingZeros", FALSE),
yaml=FALSE, tmpdir=tempdir(), tz="UTC"
yaml=FALSE, tmpdir=tempdir(), tz="UTC",
no.integer64.message=FALSE
)
}
\arguments{
Expand Down
Loading