Skip to content

Commit

Permalink
Add missing check for valid i and j
Browse files Browse the repository at this point in the history
For some reason, an xts object containing logical data with a real
(numeric) index did not receive the same treatment as all other
data/index types.

All other branches check that:
* i is not NA
* i is not > nrow(x)
* j is not > ncol(x)

Add the same check to this branch of logic.

Fixes #163.
  • Loading branch information
joshuaulrich committed Mar 19, 2017
1 parent 03b79d8 commit a57665f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/subset.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ SEXP _do_subset_xts (SEXP x, SEXP sr, SEXP sc, SEXP drop) {
real_nindex = REAL(nindex);
real_oindex = REAL(oindex);
for(i=0; i<nr; i++) {
if(int_sr[i] == NA_INTEGER)
error("'i' contains NA");
if(int_sr[i] > nrs || int_sc[j] > ncs)
error("'i' or 'j' out of range");
real_nindex[i] = real_oindex[int_sr[i]-1];
if(int_sc[j] == NA_INTEGER)
int_result[i+j*nr] = NA_INTEGER;
Expand Down

0 comments on commit a57665f

Please sign in to comment.