Report array dimensionality in obj_type_friendly()
#1832
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In vctrs, we are trying to be fairly strict about the type of
condition
invec_if_else()
. In particular, we disallow arrays from being passed ascondition
, even 1D arrays (we do this consistently acrossvec_if_else()
,list_combine()
, vec_case_when(), and
vec_replace_when()`, all of which can take logical "condition" indices).https://github.com/r-lib/vctrs/blob/f27ab24c7eb0b1d78d48bd1d39175a1ecf7d4411/src/slice-assign.c#L964-L971
Unfortunately,
obj_type_friendly()
currently reports 1D arrays as identical to vectors resulting in the following not-useful error messageI'd argue that 1D arrays should be reported as arrays by
obj_type_friendly()
. In other words, we'd have:n_dim = 0
givesvector
n_dim = 1
givesarray
n_dim = 2
givesmatrix
n_dim = 3+
givesarray
This feels right to me and allows us to report a useful distinction between vectors and 1D arrays.