R-alpha: Re: wish ``hist() returning ..'' --- and if plot=T ?

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 2 Dec 1997 12:26:32 +0100


	[R-devel instead of  R-help]

>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

    PD> Martin Maechler <maechler@stat.math.ethz.ch> writes:
    >> 
    >> >>>>> Albrecht Gebhardt <agebhard@zidsrv.sci.uni-klu.ac.at> writes:
    >> 
    Albrecht> would it be possible to change the hist() function in future
    Albrecht> R Versions to accept a "plot=F" parameter (like hist() in S
    Albrecht> it should return a list with "breaks" and "counts" in this
    Albrecht> case). This change should be very simple.
    >> 
    >> it _was_ simple, and has been in the current sources for a while now.
    >> You'll see it in version 0.60 which should be released `real soon now'.
    >> 
    >> > hist(rnorm(50), plot=F)
    >> $breaks
    >> [1] -3 -2 -1  0  1  2  3
    >> 
    >> $counts
    >> [1]  1 11 12 20  5  1

    PD> Martin: Wouldn't it be better to return

    PD> invisible(list(breaks = breaks, counts = counts))

    PD> in the plot=T case? (currently it's  invisible(NULL) )

Yes, it would be better;
I even remember having thought about it....
ahh, the reason I did not implement it, is that S-plus is different:
It returns something else for  plot=TRUE:

S> x_ rnorm(50)
S> hi_ hist(x)
S> h2_ hist(x,plot=F)
S> hi
[1] -2.5 -1.5 -0.5  0.5  1.5  2.5
S> h2
$breaks:
[1] -3 -2 -1  0  1  2  3

$counts:
[1]  1  6 14 22  6  1

---
Do we want  S-compatibility here?
(At that time, I hated the idea that the return value is so different, just
 depending on the  plot=.. value).

At the moment, I have (only here, not yet commited)

In the case of  plot=FALSE, one wants (almost) always to
work with the result (and not just see it),i.e. one can have invisible
in both cases.
Therefore, I'd propose the following ``end of hist''
 ((Shall I commit this change later today, about GMT 15.00 ?)


	......

	if(plot) {
		plot.new()
		plot.window(xlim, ylim, "")
		title(main = main, xlab = xlab, ylab = ylab, ...)
		if(axes) {
			axis(1, ...)
			axis(2, ...)
		}
		rect(breaks[-nB], 0, breaks[-1], counts,
		     col = col, border = border)
	}
	invisible(list(breaks = breaks, counts = counts))
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._