[R] seq(2,5,-2) not an error but NULL

Christian Hoffmann christian.hoffmann at wsl.ch
Mon Mar 27 11:41:37 CEST 2006


This may belong more to r-develop, but general discussion may be useful 
(for the how many-th time ?)


both result in

Error in seq.default(2, 5, -2) : wrong sign in 'by' argument

But often, if not always, mathematicians and programmers want a 
behaviour e.g. in for loops, where this statement results in an empty 
statement, that is

for (ii in seq(2,5,-2)) print(ii)

were equivalent to

for (ii in NULL) print(ii).

The relevant part in seq.default is now

             if (n < 0)
                 stop("wrong sign in 'by' argument")

but could be changed by option to


I think there should be an option to seq requiring this behaviour, or a 
specific function, may be even a special operator, e.g. %;%:

3;5 resulting in NULL.

What do you think?

Dr. Christian W. Hoffmann,
Swiss Federal Research Institute WSL
Mathematics + Statistical Computing
Zuercherstrasse 111
CH-8903 Birmensdorf, Switzerland

Tel +41-44-7392-277  (office)   -111(exchange)
Fax +41-44-7392-215  (fax)
christian.hoffmann at wsl.ch

International Conference 5.-7.6.2006 Ekaterinburg Russia
"Climate changes and their impact on boreal and temperate forests"

More information about the R-help mailing list