Skip to content

Commit a50995f

Browse files
committed
Mostly finalizing (#628).
1 parent 9539f47 commit a50995f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

NEWS.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
### Bug Fixes
1212

13-
* Fixed some issues using *collapse* and the *tidyverse* together, particularly regarding tidyverse methods for 'grouped_df' - thanks @NicChr (#645) .
13+
* Fixed some issues using *collapse* and the *tidyverse* together, particularly regarding tidyverse methods for 'grouped_df' - thanks @NicChr (#645).
14+
15+
* More consistent handling of zero-length inputs - they are now also returned in `fmean()` and `fmedian()`/`fnth()` instead of returning `NA` (#628).
16+
1417

1518
### Additions
1619

src/fnth_fmedian_fquantile.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ SEXP fnthC(SEXP x, SEXP p, SEXP g, SEXP w, SEXP Rnarm, SEXP Rret, SEXP Rnthreads
12331233
CHECK_PROB(l);
12341234

12351235
// if(l < 1) return x;
1236-
if(l < 1 || (l == 1 && nullw)) return TYPEOF(x) == REALSXP ? x : ScalarReal(asReal(x));
1236+
if(l < 1 || (l == 1 && nullw)) return TYPEOF(x) == REALSXP ? x : l < 1 ? allocVector(REALSXP, 0) : ScalarReal(asReal(x));
12371237

12381238
// First the simplest case
12391239
if(nullg && nullw && nullo) return nth_impl(x, narm, ret, Q);

tests/testthat/test-miscellaneous-issues.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,11 @@ test_that("0-length vectors give expected output", {
225225
funs <- .c(fsum, fprod, fmean, fmedian, fmin, fmax, fnth, fcumsum, fbetween, fwithin, fscale)
226226
for(i in funs) {
227227
FUN <- match.fun(i)
228-
if(i %!in% .c(fsum, fmin, fmax, fcumsum, fmedian, fnth)) {
228+
if(i %!in% .c(fsum, fmin, fmax, fcumsum)) {
229229
expect_true(all_identical(FUN(numeric(0)), FUN(integer(0)), numeric(0)))
230230
} else {
231231
expect_identical(FUN(numeric(0)), numeric(0))
232-
if(i %in% .c(fmean, fprod, fnth, fmedian)) expect_identical(FUN(integer(0)), NA_real_)
233-
else expect_identical(FUN(integer(0)), integer(0))
232+
expect_identical(FUN(integer(0)), integer(0))
234233
}
235234
}
236235
funs <- .c(fmode, ffirst, flast)

0 commit comments

Comments
 (0)