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

Eric Lecoutre lecoutre at stat.ucl.ac.be
Mon Nov 29 15:47:58 CET 2004


If I define the following list:

 > (l<-list("text-align"="right"))
[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:

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 

Anyway I will use "[[" but I dont clearly understand this behavior.


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

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be

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

More information about the R-devel mailing list