Skip to content

Commit 729c587

Browse files
committed
Fixing checks
1 parent b86e3fd commit 729c587

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

R/methods-subset.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ fa_subset1 <- function(x, ..., drop = TRUE, reshape = NULL, strict = TRUE, dimna
2222

2323
listOrEnv <- list()
2424
if(arglen == 1){
25-
tmp <- tryCatch({
26-
...elt(1)
27-
}, error = function(e){
28-
NULL
29-
})
30-
if(length(tmp)){
31-
stop("Subset FileArray only allows x[], x[i:j] or x[i,j,...] (single logical index like x[c(TRUE, ...)] is not allowed)")
25+
missing_args <- check_missing_dots(environment())
26+
if(length(missing_args) > 0 && !missing_args[[1]]){
27+
tmp <- ...elt(1)
28+
if(length(tmp)){
29+
stop("Subset FileArray only allows x[], x[i:j] or x[i,j,...] (single logical index like x[c(TRUE, ...)] is not allowed)")
30+
}
3231
}
3332

3433

src/collapse.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void collapse_complex(
318318

319319
for(int64_t jj = 0; jj < readlen; jj++){
320320
v = *(bufcplx_ptr + jj);
321-
if( remove_na && (v.i == NA_REAL || v.r == NA_REAL) ){
321+
if( remove_na && (ISNAN(v.i) || ISNAN(v.r)) ){
322322
continue;
323323
}
324324
rem = jj + buf_idx;
@@ -336,9 +336,11 @@ void collapse_complex(
336336
fct *= *(dimptr + tmp);
337337
}
338338
ret_ii = ret + rem;
339-
if( v.i == NA_REAL || v.r == NA_REAL ){ // remove_na must be false
339+
if( ISNAN(v.i) || ISNAN(v.r) ){ // remove_na must be false
340340
*ret_ii = na_cplx;
341341
continue;
342+
} else if( !remove_na && (ISNAN(ret_ii->r) || ISNAN(ret_ii->i)) ){
343+
continue;
342344
}
343345
// rem is index of ret
344346
// need to be atom

src/utils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ List test_farr_findVarInFrame_(SEXP env, std::string sym_name) {
2020
Rcpp::stop("env must be an environment");
2121
}
2222
SEXP sym = Rf_install(sym_name.c_str());
23-
SEXP result = farr_findVarInFrame(env, sym);
23+
SEXP result = PROTECT(farr_findVarInFrame(env, sym));
2424
bool is_missing = (result == R_MissingArg);
2525
// farr_findVarInFrame maps R_UnboundValue → R_NilValue, so we need
2626
// an independent check to report is_unbound correctly.
@@ -30,6 +30,7 @@ List test_farr_findVarInFrame_(SEXP env, std::string sym_name) {
3030
bool is_unbound = (Rf_findVarInFrame(env, sym) == R_UnboundValue);
3131
#endif
3232
SEXP rval = (is_unbound || is_missing) ? R_NilValue : result;
33+
UNPROTECT(1);
3334
return List::create(
3435
_["result"] = rval,
3536
_["is_unbound"] = is_unbound,
@@ -178,7 +179,7 @@ SEXP check_missing_dots(const SEXP env){
178179
if( TYPEOF(env) != ENVSXP ){
179180
Rcpp::stop("`check_missing_dots` is asking for an environment");
180181
}
181-
SEXP dots = farr_findVarInFrame(env, R_DotsSymbol);
182+
SEXP dots = PROTECT(farr_findVarInFrame(env, R_DotsSymbol));
182183

183184
std::vector<bool> is_missing(0);
184185

@@ -195,6 +196,7 @@ SEXP check_missing_dots(const SEXP env){
195196
}
196197
}
197198

199+
UNPROTECT(1);
198200
return(Rcpp::wrap(is_missing));
199201
}
200202

0 commit comments

Comments
 (0)