[Rd] seq edge cases

Jan Gleixner j@n@g|e|xner @end|ng |rom gm@||@com
Wed Nov 22 19:39:03 CET 2023


I think that, if called with |length.out=1|, |seq| and |seq.int| should 
return |start| - no matter the value of the other parameters.
Currently they always return |NaN| / error if called with |by=Inf|, for 
example.

|for (n in 4:0) print(seq(1, by=1/(n-1), length.out=n)) # [1] 1.000000 
1.333333 1.666667 2.000000 # [1] 1.0 1.5 2.0 # [1] 1 2 # [1] NaN <- this 
should be 1 # integer(0) for (n in 4:0) print(seq.int(1, by=1/(n-1), 
length.out=n)) # [1] 1.000000 1.333333 1.666667 2.000000 # [1] 1.0 1.5 
2.0 # [1] 1 2 # Error in seq.int(1, by = 1/(n - 1), length.out = n) : <- 
this should be 1, not an error # 'by' must be a finite number # 
integer(0) <- (result for n=0) |

I believe changing this would prevent quite some edge case bugs, for 
example this one:

|> colorspace::divergingx_hcl(1) Error in seq.int(1, by = -2/(n - 1), 
length.out = n2) : 'by' must be a finite number |

Do see any downside to this?

-Jan

​

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20231122/a7945fb2/attachment.sig>


More information about the R-devel mailing list