[R] Names of Greek letters stored as character strings; plotmath.

peter dalgaard pdalgd at gmail.com
Mon May 21 09:20:59 CEST 2012


On May 21, 2012, at 05:25 , Duncan Murdoch wrote:

> On 12-05-20 10:28 PM, Bert Gunter wrote:
>> Well, that's not very comforting, Duncan. It's like saying that you
>> have to read the engineering specs to drive the car successfully.
> 
> I think Robert's message that I responded to was asking for a deeper understanding than simply driving the car.  He appeared to want to know why the car worked the way it did, and describing that entirely in terms of things you can see without opening the hood is hard.

There are levels, though. For basic car driving, it might be sufficient to know that turning the steering wheel left makes the car change direction towards left. Rather soon, you will realize that it is imortant that it does so by turning the front wheels; this explains why you need to reverse into a parallel-parking space. At some point, it may become useful to know that the wheels are tangential to the curve that the car follows and that it therefore turns around a point on the line trough the rear wheels (not that that ever helped me to parallel park...).

In R, it is important to have some reasonably accurate mental image of its internal structures. For quote() and friends, the thing that you really need is the notion of a _parse tree_, i.e. the fact that expressions are not evaluated as-is, but first converted (parsed) to an internal structure that is equivalent to a list of lists:

> e <- quote(2/(3+a))
> e[[1]]
`/`
> e[[2]]
[1] 2
> e[[3]]
(3 + a)
> e[[3]][[1]]
`(`
> e[[3]][[2]]
3 + a
> e[[3]][[2]][[1]]
`+`
> e[[3]][[2]][[2]]
[1] 3
> e[[3]][[2]][[3]]
a

or, graphically (mailer permitting)

`/` +--2
    |
    +--`(`--`+` +-- 3
                |
                +-- a

Once you have this concept in mind, it should become fairly clear that the string constant "a" is fundamentally different from the variable name a.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list