Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a silent attribute to an object in R so that it doesn't print to console unless inspected directly?

Tags:

r

Is there a way to set an object's attribute such that the attribute does not print to console when the object is called (but which still allows the attribute to be inspected when attributes() is called on the object)?

Example

E.g. if x is given a random attribute

x <- 1:5
attr(x, 'some_attribute') <- "value of the attribute"

we can inspect the attribute

attributes(x)
$some_attribute
[1] "value of the attribute"

but the attribute also prints to console when the object is called

x
[1]  1  2  3  4  5
attr(,"some_attribute")
[1] "value of the attribute"

Question

Is there a way to set an attribute so that it doesn't print to console when the object is called?

That is (from the example above) such that x prints without the attribute(s) set for it

x
[1]  1  2  3  4  5
like image 615
stevec Avatar asked Oct 27 '25 23:10

stevec


1 Answers

You want the comment attribute: https://stat.ethz.ch/R-manual/R-devel/library/base/html/comment.html

comment(x) <- "This value won't print."
like image 98
Cat Bisque Avatar answered Oct 29 '25 15:10

Cat Bisque