Bug 14169 - seq.int broken (seq as well)
seq.int broken (seq as well)
Status: CLOSED INVALID
Product: R
Classification: Unclassified
Component: Misc
old
ix86 (32-bit) Windows 32-bit
: P5 normal
Assigned To: Jitterbug compatibility account
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-29 01:46 UTC by Jitterbug compatibility account
Modified: 2009-12-30 21:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2009-12-29 01:46:45 UTC
From: oehl_list@gmx.de
Full_Name: Jens Oehlschlägel
Version: 2.10.1
OS: Windows XP
Submission from: (NULL) (156.109.18.2)


# fine as expected from help page: 
# "from+by, ..., up to the sequence value less than or equal to to"
# thus 1+10=11 is not in
> seq.int(1L, 10L, by=10L)
[1] 1

# of course 1+1e7 should also not be in
# but is: wrong
> seq.int(1L, 1e7L, by=1e7L)
[1] 1e+00 1e+07

# since we use seq.int AND are within integer range, rounding should not be an
issue


> version
               _                            
platform       i386-pc-mingw32              
arch           i386                         
os             mingw32                      
system         i386, mingw32                
status                                      
major          2                            
minor          10.1                         
year           2009                         
month          12                           
day            14                           
svn rev        50720                        
language       R                            
version.string R version 2.10.1 (2009-12-14)

Comment 1 Jitterbug compatibility account 2009-12-30 21:00:28 UTC
From: Petr Savicky <savicky@cs.cas.cz>
On Mon, Dec 28, 2009 at 08:50:13PM +0100, oehl_list@gmx.de wrote:
[...]
> # fine as expected from help page: 
> # "from+by, ..., up to the sequence value less than or equal to to"
> # thus 1+10=11 is not in
> > seq.int(1L, 10L, by=10L)
> [1] 1
> 
> # of course 1+1e7 should also not be in
> # but is: wrong
> > seq.int(1L, 1e7L, by=1e7L)
> [1] 1e+00 1e+07
> 
> # since we use seq.int AND are within integer range, rounding should not be an
> issue

In my opinion, this is a documented behavior. The Details section of the help
page says

     Note that the computed final value
     can go just beyond 'to' to allow for rounding error, but (as from
     R 2.9.0) is truncated to 'to'.

Since "by" is 1e7, going by 1 more than 'to' is "just beyond 'to'".

What can be a bit misleading is the following difference between the type
of seq() and seq.int(), which is only partially documented.

  x <- seq.int(from=1L, to=10000000L, by=10000000L); typeof(x); x
  # [1] "double"
  # [1] 1e+00 1e+07

  x <- seq(from=1L, to=10000000L, by=10000000L); typeof(x); x
  # [1] "integer"
  # [1]        1 10000000

The Value section of the help page says

     Currently, 'seq.int' and the default method of 'seq' return a
     result of type '"integer"' (if it is representable as that and) if
     'from' is (numerically equal to an) integer and, e.g., only 'to'
     is specified, or also if only 'length' or only 'along.with' is
     specified.  *Note:* this may change in the future and programmers
     should not rely on it.

This suggests that we should get "double" in both cases, since all three
arguments "from", "to", and "by" are specified. I do not know, whether
having an "integer" result in seq() in the above case is intended or not.

Petr Savicky.

Comment 2 Jitterbug compatibility account 2010-01-01 18:22:00 UTC
NOTES:
 Documented behaviour!
Comment 3 Jitterbug compatibility account 2010-01-01 18:22:07 UTC
Audit (from Jitterbug):
Fri Jan  1 12:22:07 2010	ripley	changed notes
Fri Jan  1 12:22:07 2010	ripley	moved from incoming to feature&FAQ