-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fread nrows=0L fixed to work like nrows=0 #4694
Conversation
thanks @ben-schwen quick GH tip, if you include |
src/freadR.c
Outdated
@@ -126,7 +126,7 @@ SEXP freadR( | |||
if (isReal(nrowLimitArg)) { | |||
if (R_FINITE(REAL(nrowLimitArg)[0]) && REAL(nrowLimitArg)[0]>=0.0) args.nrowLimit = (int64_t)(REAL(nrowLimitArg)[0]); | |||
} else { | |||
if (INTEGER(nrowLimitArg)[0]>=1) args.nrowLimit = (int64_t)INTEGER(nrowLimitArg)[0]; | |||
if (INTEGER(nrowLimitArg)[0]>=0) args.nrowLimit = (int64_t)INTEGER(nrowLimitArg)[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm glad it works but I'm not sure why nrows=0
would work differently than nrows=0L
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually thats quite interesting. Apparently 0L
is not real and hence the second case triggers.
See also
library(inline)
is_real <- cfunction(c("x" = "ANY"), "
return ScalarLogical(isReal(x));
")
is_real(0) #returns TRUE
is_real(0L) #returns FALSE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm and we use real here because we allow nrows=Inf
to mean "everything". What about just doing as.numeric(nrows)
in the fread.R
code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would also be a possibility. But then we could also remove the else (of if (isReal(nrowLimitArg))
) branch in fread.c
since it should not be reachable anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try it out and see if we pass tests. There might be some other use case we're not thinking of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passes all tests.
Codecov Report
@@ Coverage Diff @@
## master #4694 +/- ##
=======================================
Coverage 99.42% 99.42%
=======================================
Files 73 73
Lines 14439 14440 +1
=======================================
+ Hits 14356 14357 +1
Misses 83 83
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR
R/fread.R
Outdated
@@ -26,6 +26,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="") | |||
stopifnot( isTRUEorFALSE(stringsAsFactors) || (is.double(stringsAsFactors) && length(stringsAsFactors)==1L && 0.0<=stringsAsFactors && stringsAsFactors<=1.0)) | |||
stopifnot( is.numeric(nrows), length(nrows)==1L ) | |||
if (is.na(nrows) || nrows<0L) nrows=Inf # accept -1 to mean Inf, as read.table does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not directly related to the bug but related to your PR, I guess nrows<0 is more appropriate here
Closes #4686.
fread
now also acceptsnrows=0L
and treats it likenrows=0
. Beforehand0L
was treated likenrows=Inf
.