fread nrows=0L fixed to work like nrows=0#4694
Conversation
|
thanks @ben-schwen quick GH tip, if you include |
| 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.
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.
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.
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.
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.
Try it out and see if we pass tests. There might be some other use case we're not thinking of
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.
|
MichaelChirico
left a comment
There was a problem hiding this comment.
LGTM, thanks for the PR
| @@ -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.
not directly related to the bug but related to your PR, I guess nrows<0 is more appropriate here
Closes #4686.
freadnow also acceptsnrows=0Land treats it likenrows=0. Beforehand0Lwas treated likenrows=Inf.