开发者

Adding Descriptive Text to a Variable

Is there a command, or method for adding descriptive text to开发者_如何学编程 a variable such that when you call for the str() of the variable you also see an attribute that describes what's in it?

I find, in some cases that commenting my code is simply not enough (especially when working with a lot of variables).


Brandon,

comment() and attr() can be useful here. This recent post has some really good information on this.

From the help page for comment():

x <- matrix(1:12, 3,4)
comment(x) <- c("This is my very important data from experiment #0234",
                "Jun 5, 1998")
x
comment(x)

and str(x) returns:

> str(x)
 int [1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
 - attr(*, "comment")= chr [1:2] "This is my very important data from experiment #0234" "Jun 5, 1998"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜