I'm dithering - which seq should I use?
- June 13, 2012
- 2 replies
- 16913 views
I'm rewriting a number of functions whilst sorting out my toolbox of utility functions and I've hit a slight quandry with regard to one of the most regularly used ones, seq.
seq(n) was originally written to generate simple integer sequences, primarily for use as vector indices and as test data. Consequently, I thought about its input argument, n, in terms of the number of elements and mentally regarded it as an integer with no thought for other interpretations (apart from arrays and range definitions, which seq passed to my other primary tool, vec).
However, I have several variants of seq (often with additional arguments) that allow me to generate more complex sequences, including string sequences. The downside is that it necessitates a change in world view to looking at n as the upper limit of a sequence (and implied lower limit for negative numbers). This will involve a further rewrite of several functions to accomodate the effect this has upon zero-based indices (positive n will now give a vector of n+1 elements). I also get a different response for 0 and negative numbers, which previously generated errors (on the not entirely unreasonable basis that you shouldn't have a vector with zero or a negative amount elements) but now return valid sequences (if, in the case of 0, you can call a one-element array a sequence).
My goal in tool generation is to keep the tools small and simple with as few arguments as possible, and preferably with short meaningful names.
The question is does this new form of seq look worth trouble? It's larger than I like tools to be (but I do have some larger ones), is fairly complex in its treatment of its argument and, although I'm happyish with most of the interpretations, they may not be so for others or there may be better ones.
All comments gratefully received.
Thank you.
Stuart
