r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
282 stars 65 forks source link

Misleading error messages when subscripting homogenous list #1915

Open tzakharko opened 4 months ago

tzakharko commented 4 months ago

Subscripting a homogenous list by name throws an error "corrupt \<var>: no names". I think it would be better to report something like "\<var> has no names". Using the term "corrupt" here may confuse the user into thinking that something went terribly wrong at the R side, where the simple fact is that they have been accessing the object incorrectly (I already had a user reporting a bug because of this message).

Current behavior:

x <- vctrs::list_of(1, 2, 3)
x$aa
#> Error: Corrupt x: no names

Suggested behavior:

x <- vctrs::list_of(1, 2, 3)
x$aa
#> Error: x has no named elements