From murdoch at stats.uwo.ca  Mon Nov 29 16:09:40 2004
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon Nov 29 16:09:40 2004
Subject: [Rd] Differences between "$" and "[["
In-Reply-To: <6.0.1.1.2.20041129153016.0393fec0@stat4ux.stat.ucl.ac.be>
References: <6.0.1.1.2.20041129153016.0393fec0@stat4ux.stat.ucl.ac.be>
Message-ID: <ukemq0lvmqcmbgmjma95fchj7la2q7divr@4ax.com>

On Mon, 29 Nov 2004 15:47:58 +0100, Eric Lecoutre
<lecoutre@stat.ucl.ac.be> wrote :

>
>Hi,
>
>If I define the following list:
>
> > (l<-list("text-align"="right"))
>$"text-align"
>[1] "right"
>
>I know that I can't use l$text-align, as the parser will find a '-' operation.
>If I want (need) to use special names, as "text-align", I have to enclose 
>it between "". So I can use:
>
>l$"text-align" or l[["text-align"]]
>
>If now I have the text "text-align" defined in a variable:
>p<-"text-align"
>
>I can use:
> > l[[p]]
>[1] "right"
>
>But I can't use l$p
>
>where as it is said in the help page that 'x$name' is equivalent to 
>'x[["name"]]'.
>
>Anyway I will use "[[" but I dont clearly understand this behavior.

I think you do understand it.  From the line above, l$p would be
equivalent to l[["p"]], which is clearly different from l[[p]].

But since l$"text-align" is harder to construct than l[["text-align"]]
when "text-align" is stored in p, why bother?

Duncan Murdoch


[Rd] Differences between "$" and "[["
Duncan Murdoch