Is there an easier way to access attributes of a class in R, can I use dot notation?

后端 未结 4 1828
暖寄归人
暖寄归人 2021-01-30 17:46

I have created an object in R that contains several attributes. How can I easily access them?

I can do:

attr(x, attributeName)

or:

4条回答
  •  走了就别回头了
    2021-01-30 17:50

    probably there is no built-in function that is counter part of . in C++, but you can define it like this:

    > `%.%` <- function(o, a) attr(o, as.character(substitute(a)))
    > x <- 1
    > attr(x, "orz") <- 2
    > x%.%orz
    [1] 2
    

提交回复
热议问题