[Rd] History of seq and seq.int

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 5 08:09:28 CEST 2010


The history is open for all to see. E.g. from the NEWS file (ONEWS in 
pre-2.12.0) entry for R 2.4.0

     o	There is a new primitive seq.int() which is slightly more
 	restricted than seq() but often very much faster, and new
 	primitives seq_along() and seq_len() which are faster still.

It isn't just complex values: seq.default() dispatches on methods for 
e.g. arithmetic so is potentially quite a lot more general.  And if 
you look back, seq() was in R 'for ever' as an interpreted generic 
function -- its peculiarities are taken from blue-book S (although not 
necessarily documented there).

We provide faster versions for use where needed -- but it is rather 
rare that seq() takes up more than a tiny proportion of the run time 
of an R task (and we do provide tools to find out).  Those faster 
versions are used in R's own code where suitable (and as I discovered 
recently, in a couple of places where not).

On Wed, 29 Sep 2010, Radford Neal wrote:

> I wonder what is the history of "seq" and "seq.int"?
>
>> From "help(seq)", one reads that "'seq.int' is an internal generic
> which can be much faster but has a few restrictions".  And indeed,
> "seq.int(1,99,by=2)" is over 40 times faster than "seq(1,99,by=2)" in
> a quick test I just did.  This is not surprising given that "seq" is
> written in R whereas "seq.int" is a primitive written in C.  The only
> documented restriction on "seq.int" that I can see is that it won't
> produce complex-valued sequences.
>
> It would be nice if the 40-times-faster version could replace the slow
> version, if it can be made to do the same thing.  But is there some
> reason I don't see that this makes this hard?  Was the C version the
> original, and then someone decided that complex number support was
> essential, and most easily obtained by translating it to R?  (The R
> code and C code are very parallel, so there was certainly a
> translation rather a rewrite one way or the other.)  Or was the
> original in R, and someone rewrote it in C for speed, but stopped just
> short of being able to replace the R version with the C version
> because they didn't implement complex-valued sequences?  Or is there
> some other feature that's missing from seq.int?

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list