Title: | Persist Attributes Across Data Operations |
---|---|
Description: | In base R, object attributes are lost when objects are modified by common data operations such as subset, filter, slice, append, extract etc. This packages allows objects to be marked as 'sticky' and have attributes persisted during these operations or when inserted into or extracted from list-like or table-like objects. |
Authors: | Christopher Brown [aut, cre], Decision Patterns [cph] |
Maintainer: | Christopher Brown <[email protected]> |
License: | GPL-2 | file LICENSE |
Version: | 0.5.6.1 |
Built: | 2025-01-10 05:33:03 UTC |
Source: | https://github.com/decisionpatterns/sticky |
These are internal functions for the sticky package. They are not
exported and should not be used directly. Instead use the proper interface,
sticky
and unstick
.init(x) .deinit(x)
.init(x) .deinit(x)
x |
vector |
.init
: initializes the class
.deinit
: uninitialize the class
These are internals functions not to be called directly, please use the
interfaces, sticky
and unsticky
.
sticky
and unsticky
# - tk
# - tk
Extract
## S3 method for class 'sticky' x[...]
## S3 method for class 'sticky' x[...]
x |
sticky; object to extract from |
... |
additional parameters |
Implements '[' for sticky attributes. This methods ensures that existing attributes are propagated forward.
attributes
, specifically mostattributes
Append elements to sticky object
append(x, ...)
append(x, ...)
x |
sticky object |
... |
additional arguments to
|
print a sticky object which mostly delegates it the the next method.
## S3 method for class 'sticky' print(x, ...)
## S3 method for class 'sticky' print(x, ...)
x |
sticky object |
... |
further arguments passed to or from other methods. |
prints a sticky object; this is also the default method for sticky objects
An invisible copy of x
.
x <- sticky(1:3) print(x) x
x <- sticky(1:3) print(x) x
Persist Attributes
sticky(x) unstick(x) unsticky(x) is.sticky(x) sticky_all(x)
sticky(x) unstick(x) unsticky(x) is.sticky(x) sticky_all(x)
x |
objects to have attributes preserved. |
sticky
creates objects whose attributes are resilient to subsetting and
placing in containers such as lists, data.frames and data.tables.
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
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
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
Subset elements to sticky object
## S3 method for class 'sticky' subset(x, ...)
## S3 method for class 'sticky' subset(x, ...)
x |
sticky object |
... |
additional arguments to
|