R-alpha: Re: greedy wishing 'cdfplot' : plot.step(.) + deparse(substitute(..))

Kurt Hornik (hornik@ci.tuwien.ac.at)
Thu, 23 Jan 1997 13:09:29 +0100

Date: Thu, 23 Jan 1997 13:09:29 +0100
Message-Id: <199701231209.NAA12355@aragorn.ci.tuwien.ac.at>
From: Kurt Hornik <hornik@ci.tuwien.ac.at>
To: Martin Maechler <maechler@stat.math.ethz.ch>
Subject: R-alpha: Re: greedy wishing 'cdfplot' :  plot.step(.) + deparse(substitute(..))
In-Reply-To: <9701220751.AA02041@>

>>>>> On Wed, 22 Jan 97 08:51:18 +0100,
>>>>> Martin Maechler <maechler@stat.math.ethz.ch> said:

> Here is one of our 'goodies' that I wrote a while ago for S-plus.
> It is a general  'step function' plotter.

> It runs ok in R
> 	(I see some rounding 'problem' at the ends(Example w/ 'cad = F'),
> 	 and an 
>>> R 'incompatibility' / 'bug': 
>>> The  xlab =  deparse(substitute(..))
>>> gives not what I expected (and what S gives)..

> Could the persons who find out please  post (or e-mail me) the result?


Works very nice indeed.

Re bug, if I understand things correctly, this is really a `feature'.
>From the paper of R&R in the Journal of Computational and Graphical
Statistics, evaluation in R is `lazier' than in S, so things are just
evaluated when needed.

So in your code, the deparse(substitute()) statements in the function
header are only evaluated when plot() is called.

To fix the problem one could either do

	plot.step <- function(ti, <...>, xlab = NULL, <...>)

and start with

	xlab <- deparse(substitute(ti))

or more easily add

	eval({xlab; ylab})

after the function header.

r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch

>->->- Local variables:
>->->- mode: text
>->->- outline-regexp: ">->-\\|From \\|Subject:"
>->->- eval: (outline-minor-mode 1)
>->->- eval: (hide-body)
>->->- eval: (show-entry) ;the first one
>->->- End:
>->-> You can look at this file from within GNU emacs,
>->-> using outline-minor-mode ["Headings", "Show", "Hide" Menus under X11]
>->-> --
>->-> OR also simply by 
>->->	/usr/ucb/mail -f  THIS_FILE