Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected failures when vector inherits from character #497

Closed
hadley opened this issue Jul 22, 2019 · 3 comments · Fixed by #656
Closed

Unexpected failures when vector inherits from character #497

hadley opened this issue Jul 22, 2019 · 3 comments · Fixed by #656

Comments

@hadley
Copy link
Member

@hadley hadley commented Jul 22, 2019

library(vctrs)
library(glue)

x <- glue("abc")
vec_c(x, x)
#> Only bare vectors have shapes.
    █
 1. ├─vctrs::vec_c(x, x)
 2. ├─vctrs:::vec_type2_dispatch(x = x, y = y, x_arg = x_arg, y_arg = y_arg)
 3. ├─vctrs::vec_ptype2.character(x = x, y = y, x_arg = x_arg, y_arg = y_arg)
 4. └─vctrs:::vec_ptype2.character.character(...)
 5.   └─vctrs:::shape_match(character(), x, y)
 6.     └─vctrs:::shape_common(x, y)
 7.       ├─vctrs:::n_dim2(shape(x), shape(y))
 8.       └─vctrs:::shape(x)

Created on 2019-07-22 by the reprex package (v0.3.0)

From tidyverse/tidyr#676.

@hadley

This comment has been minimized.

@yutannihilation

This comment has been minimized.

Copy link
Contributor

@yutannihilation yutannihilation commented Jul 24, 2019

Is this issue only about the error message? I think no error is the expected result.

@lionel-

This comment has been minimized.

Copy link
Member

@lionel- lionel- commented Oct 4, 2019

x <- structure(letters[1:3], class = "foo")
vctrs::vec_match(x, x)
#> [1] 1 2 3

x <- structure(letters[1:3], class = "character")
vctrs::vec_match(x, x)
#> <error/rlang_error>
#> Only bare vectors have shapes.
#> Backtrace:
#>  1. vctrs::vec_match(x, x)
#>  4. vctrs:::vec_ptype2.character.character(...)
#>  5. vctrs:::shape_match(character(), x, y)
#>  6. vctrs:::shape_common(x, y)
#>  8. vctrs:::shape(x)
@lionel- lionel- changed the title Uninformative error message Unexpected failures when vector inherits from character Oct 4, 2019
lionel- added a commit to r-lib/tidyselect that referenced this issue Oct 4, 2019
Until r-lib/vctrs#497 is fixed
hadley added a commit that referenced this issue Nov 11, 2019
Closes #593

Currently failing due to #497
hadley added a commit that referenced this issue Nov 11, 2019
* If neither x nor y are objects, preserve their shape
* Otherwise preserve the underlying base type

I think this is correct because if the class vector includes (e.g.) "character", that's an assertion that the object is a character vector. To preserve attributes and class, you'd need to provide a vec_ptype2 method.

Fixes #497
@hadley hadley closed this in #656 Nov 12, 2019
hadley added a commit that referenced this issue Nov 12, 2019
* If neither x nor y are objects, preserve their shape
* Otherwise preserve the underlying base type

I think this is correct because if the class vector includes (e.g.) "character", that's an assertion that the object is a character vector. To preserve attributes and class, you'd need to provide a vec_ptype2 method.

Fixes #497
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.