chuck | R Documentation |
chuck()
implements a generalised form of [[
that allow you to index
deeply and flexibly into data structures. If the index you are trying to
access does not exist (or is NULL
), it will throw (i.e. chuck) an error.
chuck(.x, ...)
.x |
A vector or environment |
... |
A list of accessors for indexing into the object. Can be an positive integer, a negative integer (to index from the right), a string (to index into names), or an accessor function (except for the assignment variants which only support names and positions). If the object being indexed is an S4 object, accessing it by name will return the corresponding slot. Dynamic dots are supported. In particular, if
your accessors are stored in a list, you can splice that in with
|
pluck()
for a quiet equivalent.
x <- list(a = 1, b = 2)
# When indexing an element that doesn't exist `[[` sometimes returns NULL:
x[["y"]]
# and sometimes errors:
try(x[[3]])
# chuck() consistently errors:
try(chuck(x, "y"))
try(chuck(x, 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.