0

I have been reading the "R Language Definition" PDF file downloaded from here. And on page 11 I read this:

page 11 of the pdf file

I wonder what is the difference between the attr and the attr<-. Thanks a lot.

Forester
  • 135
  • 5
  • 1
    `attr` gets attributes eg `attr(iris,"class")`, `<-` assigns/allows you to modify – NelsonGon May 21 '20 at 15:29
  • 1
    See [also](https://stackoverflow.com/questions/1741820/what-are-the-differences-between-and-assignment-operators-in-r) – NelsonGon May 21 '20 at 15:42
  • Than you all guys. From all the answers I conclude that, both `attr` and `attr<-` are functions. And they are similar to setters and getters in Java respectively. I hpoe I am right. – Forester May 22 '20 at 05:06

1 Answers1

1

"attr" get specific attributes of an object.

"attr<-" an object, the new value of the attribute, or NULL to remove the attribute.

Eric
  • 2,699
  • 5
  • 17
  • 1
    When you say `attr` can _set_ an attribute, it's actually `attr<-` that sets the attribute. That is, when you do `attr(x, "key") <- value`, this is actually calling `'attr<-'(x, "key", value)` – Allan Cameron May 21 '20 at 15:38