Skip to content

Commit

Permalink
Add additional example for packer
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Sep 18, 2024
1 parent ba9417c commit e50c979
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions R/packer.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@
##' fixed = list(d = data.frame(n = 1:3, m = runif(3))))
##' p$unpack(1:2)
##' p$pack(p$unpack(1:2))
##'
##' # The example from above, where we create a symmetric 2 x 2 matrix
##' # from a 3-element vector, alongside a scalar:
##' p <- monty_packer(
##' scalar = "a",
##' array = list(b_flat = 3),
##' process = function(p) list(b = matrix(p$b_flat[c(1, 2, 2, 3)], 2, 2)))
##'
##' # Unpacking we see "b_flat" is still in the list, but "b" is our
##' # symmetric matrix:
##' p$unpack(1:4)
##'
##' # The processed elements are ignored on the return pack:
##' p$pack(list(a = 1, b_flat = 2:4, b = matrix(c(2, 3, 3, 4), 2, 2)))
##' p$pack(list(a = 1, b_flat = 2:4))
monty_packer <- function(scalar = NULL, array = NULL, fixed = NULL,
process = NULL) {
call <- environment()
Expand Down
15 changes: 15 additions & 0 deletions man/monty_packer.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e50c979

Please sign in to comment.