[R] Integers in S-Plus and R

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Sep 15 09:25:39 CEST 2003


On Sun, 14 Sep 2003, Spencer Graves wrote:

> 	  I wish to comment on interesting and inconsistent behavior of both 
> S-Plus and R with integers.

I think both are consistent: they are just different from each other.

> 	  In R 1.7.1 for Windows, is.integer(2) is FALSE, though 
> is.integer(1:2) and is.integer(max(1:2)) are both TRUE.  S-Plus 6.1 
> produces TRUE for all three cases.

Yes, that's as documented.  Note that `2' was not integer in S-PLUS 1.x to 
4.x (including 2000), so this is rather an inconsistency in S-PLUS 
versions.

> 	  Meanwhile, as.integer(1e111) produces NA in R 1.7.1 and 2147483647 in 
> S-Plus 6.1.  This behavior is consistent with the documentation in both 
> cases:  R says, "The answer will be `NA' unless the coercion succeeds." 
>   S-Plus says, "The numbers are truncated (moved to the closest integer 
> ...)."
> 
> 	   Just one more thing to consider when trying to produce transportable 
> scripts.

Not that in porting code (both ways) I have ever found either to be a 
problem.

-- 
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-help mailing list