Henrik Bengtsson
2018-Sep-02 04:54 UTC
[Rd] ROBUSTNESS: a:b to give an error when length(a) > 1 or length(b) > 1 - not just a warning
For the construct a:b, we get an error if either 'a' or 'b' is empty, e.g.> x <- integer(0) > x:3Error in x:3 : argument of length 0> 3:xError in 3:x : argument of length 0 However, for length(a) > 1 or length(b) > 1, we only get a warning;> x <- 1:2 > x:3[1] 1 2 3 Warning in x:3 : In x:3 : numerical expression has 2 elements: only the first used> 3:x[1] 3 2 1 Warning message: In 3:x : numerical expression has 2 elements: only the first used I'd like to suggest to update R to produce an *error* whenever length(a) != 1 or length(b) != 1. For example,> x <- 1:3 > x:3Error in x:3 : argument is not of length one> 3:xError in 3:x : argument is not of length one The code involved is in the native function do_colon() of src/main/seq.c. /Henrik