Why 1:length(x) Fails in R (and How to Use seq_along)
In R, writing for (i in 1:length(x)) over an empty vector x causes the loop to run twice. This happens because 1:0 generates a descending sequence of [1, 0]. To prevent this bug, use the idiomatic seq
doogal.dev4 min read