purrr icon indicating copy to clipboard operation
purrr copied to clipboard

Better error messages in `chuck()`

Open mgirlich opened this issue 4 years ago • 0 comments

I think the error messages in chuck are sometimes a bit confusing and could be more understandable and detailed:

purrr::chuck(list(a = list(b = 1)), "a", "c")
#> Error: Can't find name `c` in vector

# Proposal:
# Can't find name `c` (index 2) in `.x[["a"]]`
# (i) `.x[["a"]]` has names `b`

purrr::chuck(list(a = 1), "a", 2)
#> Error: Index 2 exceeds the length of plucked object (2 > 1)

# Proposal:
# Can't extract element 2 (index 2) of `.x[["a"]]`
# (i) `.x[["a"]]` has length 1

purrr::chuck(list(a = NULL), "a", 1)
#> Error: Plucked object can't be NULL

# Proposal:
# Can't extract element 1 (index 2) from `.x[["a"]]`
# (i) `.x[["a"]]` is NULL

purrr::chuck(list(a = list()), "a", "b")
#> Error: Plucked object must have at least one element

# Proposal:
# Can't extract name `b` (index 2) from `.x[["a"]]`
# (i) `.x[["a"]]` is empty

purrr::chuck(list(a = list(1, 2)), "a", "b")
#> Error: Index 2 is attempting to pluck from an unnamed vector using a string name

# Proposal:
# Can't extract name `b` (index 2) from `.x[["a"]]`
# (i) `.x[["a"]]` has no names

Created on 2020-08-13 by the reprex package (v0.3.0)

mgirlich avatar Aug 13 '20 06:08 mgirlich