[Rd] integer overflow

roger koenker rkoenker at uiuc.edu
Wed Sep 1 18:16:36 CEST 2004

I had a question from a SparseM  user this morning who wanted to do 
like this:  (his dimensions, my data)

ia <- sample(1:52993,351718,replace=TRUE)
ja <- sample(1:52993,351718,replace=TRUE)
ra <- rnorm(351718)
dim <- as.integer(rep(52993,2))
A <- new("matrix.coo",ra=ra,ia=ia,ja=ja,dim=dim)

The last step failed because validity checking for objects of class 
wanted to test whether  length(ra)  > prod(dim), but unfortunately I'd 
the test as nrow*ncol and both were integers of size 52993 so the 
produced an integer overflow.  I see in R-help that there was some 
of this sort of thing with sum() and it appears that perhaps prod was 
also adapted
to avoid this problem.  I'm just wondering whether there was some more 
lesson to be learned here.  Other than the well-known "expect the 

url:	www.econ.uiuc.edu/~roger        	Roger Koenker
email	rkoenker at uiuc.edu			Department of Economics
vox: 	217-333-4558				University of Illinois
fax:   	217-244-6678				Champaign, IL 61820

More information about the R-devel mailing list