sticky {sticky} | R Documentation |
sticky
Description
Persist Attributes
Usage
sticky(x)
unstick(x)
unsticky(x)
is.sticky(x)
sticky_all(x)
Arguments
x |
objects to have attributes preserved. |
Details
sticky
creates objects whose attributes are resilient to subsetting and
placing in containers such as lists, data.frames and data.tables.
References
This has been asked and written about numerous times on Stack Overflow. The first has a fairly comprehensive list to others SO discussions.
http://stackoverflow.com/questions/23991060/loss-of-attributes-despite-attempts-to-preserve-them
http://stackoverflow.com/questions/10404224/how-to-delete-a-row-from-a-data-frame-without-losing-the-attributes
http://stackoverflow.com/questions/23991060/loss-of-attributes-despite-attempts-to-preserve-them
http://stackoverflow.com/questions/23841387/approaches-to-preserving-objects-attributes-during-extract-replace-operations
http://stackoverflow.com/questions/13432519/indexing-operation-removes-attributes
Examples
x <- 1:5
attr(x, 'foo') <- 'bar'
x <- x[1:3]
attr(x,'foo') # NULL
x <- sticky(1:5)
attr(x, 'foo') <- 'bar'
x_1 <- x[1:3]
attr(x_1, 'foo') # bar
x_2 <- unstick(x)
x_2 <- x[1:3]
attr(x_2,'foo') # NULL
is.sticky(x) # TRUE