sticky: sticky

Description Usage Arguments Details References Examples

View source: R/sticky.R

Description

Persist Attributes

Usage

1
2
3
4
5
6
7
8
9

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  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

decisionpatterns/sticky documentation built on March 24, 2020, 12:14 a.m.