-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Prof Brian Ripley
Sent: Thursday, March 27, 2008 3:17 AM
To: Christos Hatzis
Cc: r-help at r-project.org
Subject: Re: [R] Rule for accessing attributes?
Oh please don't recommend misuse of @ to those already confused.
@ is for accessing slots in S4 objects. This 'works' because
they happen to be stored as attributes. See the help page
(and the warning that it does no checking - we may change that).
Similarly,
plt$title <- "My Title"
works because the package maintainer (of ggplot2,
unmentioned?) has chosen to set things up that way. R is
very flexible, and there is plenty of scope for package
authors to do confusing things.
On Thu, 27 Mar 2008, Christos Hatzis wrote:
You need to use the '@' operator to directly access attributes (not
elements) of objects:
[1] "x" "y" "z"
See ?'@' for more details.
-Christos
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Tribo Laboy
Sent: Thursday, March 27, 2008 12:16 AM
To: r-help at r-project.org
Subject: [R] Rule for accessing attributes?
Hi !
I am a new user and quite confused by R-indexing.
Make a list and get the attributes
lst <- list(x = 1:3, y = 4:6, z = 7:9)
attributes(lst)
This returns:
$names
[1] "x" "y" "z"
I can easily do:
nm <-names(lst)
or
nm <-attr(lst,"names")
which both return the assigned names of the named list
then this doesn't work:
lst$names
?
I am confused ... Moreover, I noticed that some of the
plot objects returned by ggplot) also have attributes when
the 'attributes' function, but they are accessible by the
(e.g.
xydf <- data.frame(x = 1:5, y = 11:15) plt <- ggplot(data = xydf,
aes(x = x,y = y)) + geom_point()
attributes(plt)
Now we can change the title:
plt$title <- "My Title"
plt
So is it some inconsistency or am I missing something important?