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

From: Eric Lecoutre <lecoutre_at_stat.ucl.ac.be>
Date: Tue 30 Nov 2004 - 01:47:58 EST

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.

Best,

Eric
Eric Lecoutre
UCL / Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium

tel: (+32)(0)10473050
lecoutre@stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

If the statistics are boring, then you've got the wrong numbers. -Edward Tufte



R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue Nov 30 02:00:52 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 09:01:51 EST