Haven't looked at the code but guess it's index mistakes being silently treated to variable recycling. I assume what you want is v.term[(i-1):i] with i=8, it's 8-1:8, which expands to c(8,8,8,8,8,8,8,8)-c(1,2,3,4,5,6,7,8) -> c(7,6,5,4,3,2,1,0)So (8-1):8 asks for the 7 and 8th indices whereas 8-1:8 asks for the 7th till 1st and then silently throws away 0 since it's treated as an empty integer vector internally (silently again!).I'm sure this is noted in the R Inferno or at least similar.
www.burns-stat.com/pages/Tutor/R_inferno.pdf