I don't disagree that it appears that way ... but if this is ever productionized (used in an automated fashion where it is feasible that it is just
mylist <- c("TI - a", "AU - b")
, then I argue it's much better to be defensive up-front. Also, with "budding programmers", I find it best to recommend solutions that are more robust ... or at least note the assumption in the answer. I personally would be interested in some "agent" in R that looks for the use of
1:length(...)
and produces a message or warning, to warn of potential problems ... perhaps that's the "Hal9000" of R parsers :-) —
r2evans 39 secs ago