Skip to content

Commit

Permalink
adjusted any colno. > ncol to 0L
Browse files Browse the repository at this point in the history
  • Loading branch information
nitish jha authored and nitish jha committed Apr 11, 2024
1 parent 1de9230 commit 6bc4fd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions inst/tests/nafill.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ test(4.21, colnamesInt(dt, NULL), seq_along(dt))
test(4.22, colnamesInt("asd", 1), error="must be data.table compatible")
test(4.23, colnamesInt(dt, 1, check_dups="a"), error="check_dups")
test(4.24, colnamesInt(dt, c("a", "e"), skip_absent=TRUE), c(1L,0L))
test(4.25, colnamesInt(dt, c(1L, 4L), skip_absent=TRUE), c(1L,4L))
test(4.26, colnamesInt(dt, c(1, 4), skip_absent=TRUE), c(1L,4L))
test(4.25, colnamesInt(dt, c(1L, 4L), skip_absent=TRUE), c(1L,0L))
test(4.26, colnamesInt(dt, c(1, 4), skip_absent=TRUE), c(1L,0L))
test(4.27, colnamesInt(dt, c("a", NA), skip_absent=TRUE), c(1L,0L))
test(4.28, colnamesInt(dt, c(1L, 0L), skip_absent=TRUE), error="received non-existing column*.*0")
test(4.29, colnamesInt(dt, c(1, -5), skip_absent=TRUE), error="received non-existing column*.*-5")
test(4.30, colnamesInt(dt, c(1, 4), skip_absent=NULL), error="skip_absent must be TRUE or FALSE")
test(4.31, colnamesInt(dt, c(1L, 1000L), skip_absent=TRUE), c(1L,1000L))
test(4.31, colnamesInt(dt, c(1L, 1000L), skip_absent=TRUE), c(1L,0L))
names(dt) <- NULL
test(4.32, colnamesInt(dt, "a"), error="has no names")

Expand Down
2 changes: 2 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ SEXP colnamesInt(SEXP x, SEXP cols, SEXP check_dups, SEXP skip_absent) {
for (int i=0; i<nc; ++i) {
if ((!bskip_absent && icols[i]>nx) || (icols[i]<1))
error(_("argument specifying columns received non-existing column(s): cols[%d]=%d"), i+1, icols[i]); // handles NAs also
else if(bskip_absent && icols[i]>nx)
icols[i] = 0L;
}
} else if (isString(cols)) {
SEXP xnames = PROTECT(getAttrib(x, R_NamesSymbol)); protecti++;
Expand Down

0 comments on commit 6bc4fd0

Please sign in to comment.