Skip to content
Back to formatted view

Raw Message

Message-ID: <4192B5BD.4070103@pdf.com>
Date: 2004-11-11T00:43:41Z
From: Sundar Dorai-Raj
Subject: substitute/paste question for using Greek in plot titles
In-Reply-To: <4192B177.5020109@usq.edu.au>

Peter Dunn wrote:

> Hi all
> 
> I am having troubles making sense of why code (1)
> below fails but code (2) below works.
> 
> Code (1):
> 
>  > phi.1 <- 1
>  > plot(0 ~ 0,
> + main=substitute(paste("A vaue for ",phi," = ",phival), 
> list(phival=phi.1)) )
> 
> Error in paste("The two deviances for ", phi, " = ", 2) :
>         Object "phi" not found
> 
> But this works:
> 
> Code (2):
>  > plot(0,0,
> + main=substitute(paste("A value for ",phi," = ",phival), 
> list(phival=phi.1)) )
>  >
> 
> It appears that if the plot command takes the formula style entry,
> the substitue/paste fails.
> 
> Is this documented as a feature (I couldn't find it if that is the
> case), or is it a bug?  If it is a feature, it is a subtle difference
> between (1) and (2) that has potential to be quite frustrating!
> 
> Perhaps I should just upgrade to version 2.0.0, though I can't see
> anything in the Release Notes that might cause this.
> 
> Thanks.
> 
> P.
> 
>  > version
>          _
> platform i686-pc-linux-gnu
> arch     i686
> os       linux-gnu
> system   i686, linux-gnu
> status
> major    1
> minor    9.1
> year     2004
> month    06
> day      21
> language R
> 
> 

Peter,

Because in the first couple of lines of plot.formula we see this:

dots <- m$...
dots <- lapply(dots, eval, data, parent.frame())

which for your case is equivalent to:

expr <- substitute(paste("A vaue for ",phi," = ",phival), 
list(phival=phi.1))
eval(expr)

which returns an error saying "phi" cannot be found which is the correct 
behaviour of eval. I'll let others comment on whether or not this is a 
bug in plot.formula but you can always get around it by calling title:

plot(0 ~ 0)
title(main = expr)

which is exactly what your second example is doing in plot.default.

HTH,

--sundar