Henrik Bengtsson
2011-Apr-04 04:11 UTC
[Rd] Inconsistency: sort(NULL)/sort.int(NULL) does not throw an error, cf. order(NULL), sort.int(NULL, index.return=TRUE), ...
Hi, while backtracking why sort(NULL) gives a warning, and acknowledging that NULL is not the same as an empty vector and sort(NULL) is bad coding, I discovered the following inconsistency of sort.int():> x <- NULL> sort(x)Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' NULL> sort.int(x)Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' NULL> sort.int(x, index.return=TRUE)Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' Error in sort.list(x, decreasing = decreasing) : argument 1 is not a vector> sort.int(x, partial=1)Warning in is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' Error in sort.int(NULL, partial = 1) : only atomic vectors can be sorted> order(x)Error in order(x) : argument 1 is not a vector Using an empty vector behaves correctly, e.g. x <- character(0). For consistency, should sort.int(NULL) also give an error? If so, that would result in sort(NULL) throwing an error too, which might have lots of implications to code/package using NULL as an empty vector. Alternatively, if leaving sort.int(NULL) as is, maybe it would make sense to remove the non-informative warning, e.g. by having sort.int() testing for: if (is.null(x) && (!is.null(partial) && !index.return)) { return(NULL); } or replace it with an informative warning on trying to use sort.int() to sort NULL. The above is the case for R version 2.13.0 beta (2011-03-31 r55221) and R version 2.14.0 Under development (unstable) (2011-04-02 r55254). /Henrik
Reasonably Related Threads
- sort.int(c(2, NA, 4), index.return=TRUE, na.last=NA, method)$ix differ for method="radix" and "shell"/"quick" (+ new default in R-devel)
- Problem running "make bitmapdll" with R-2.13 beta r55221 on Windows
- '==' operator: inconsistency in data.frame(...) == NULL
- '==' operator: inconsistency in data.frame(...) == NULL
- '==' operator: inconsistency in data.frame(...) == NULL