Aliases: box new_box is_box unbox
Keywords:
### ** Examples boxed <- new_box(letters, "mybox") is_box(boxed)
[1] TRUE
is_box(boxed, "mybox")
[1] TRUE
is_box(boxed, "otherbox")
[1] FALSE
unbox(boxed)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z"
# as_box() avoids double-boxing: boxed2 <- as_box(boxed, "mybox") boxed2
[[1]] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z" attr(,"class") [1] "mybox" "rlang_box"
unbox(boxed2)
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z"
# Compare to: boxed_boxed <- new_box(boxed, "mybox") boxed_boxed
[[1]] [[1]] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z" attr(,"class") [1] "mybox" "rlang_box" attr(,"class") [1] "mybox" "rlang_box"
unbox(unbox(boxed_boxed))
[1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z"
# Use `as_box_if()` with a predicate if you need to ensure a box # only for a subset of values: as_box_if(NULL, is_null, "null_box")
[[1]] NULL attr(,"class") [1] "null_box" "rlang_box"
as_box_if("foo", is_null, "null_box")
[1] "foo"