[Rd] hist( ) fails with 'Inf' values unlike plot( ) (PR#7220)

epurdom at stanford.edu epurdom at stanford.edu
Thu Sep 9 18:46:34 CEST 2004

Full_Name: Elizabeth Purdom
Version: 1.9.1
OS: Windows
Submission from: (NULL) (

hist() fails if encounters 'Inf' value, rather than giving warning and removing.
Other graphics, like plot(), don't have this problem. It's actually rather
confusing if you are taking the log of data real valued data with a few
non-positive numbers. hist() works fine in this situation unless you happen to
have an exact 0, as oppose to just negative numbers. Then log(0)=Inf while
log(-1)=NA and NA values are removed by the program while Inf kills it. At least
a better error message would be good, because as it is, it looks like the
program can't handle NAs. 

> x<-seq(-5,100,by=1)
##Gives error, no output
> hist(log(x))
Error in pretty(range(x), n = breaks, min.n = 1) : 
        NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning message: 
NaNs produced in: log(x) 
##Gives log() warning
> hist(log(x)[!is.infinite(log(x))])
Warning messages: 
1: NaNs produced in: log(x) 
2: NaNs produced in: log(x)

More information about the R-devel mailing list