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

Inconsistent handling of NAs in vec_c for vctrs_vctr #1917

Closed
fabian-s opened this issue Mar 8, 2024 · 1 comment
Closed

Inconsistent handling of NAs in vec_c for vctrs_vctr #1917

fabian-s opened this issue Mar 8, 2024 · 1 comment

Comments

@fabian-s
Copy link

fabian-s commented Mar 8, 2024

Concatenating a numeric NA to a vector works, anything else does not:

library(vctrs)

new_vecreprex <- function(x = 1){
  new_vctr(as.list(x), class = "vecreprex", 
           meta = "very important info, must be preserved")
}

a <- new_vecreprex(2:3)

c(a, NA) |> str() #great!
## vecreprx [1:3] 
## $ : int 2
## $ : int 3
## $ : NULL
## @ meta: chr "very important info, must be preserved"

c(NA, a) |> str() #fails, loses class attributes etc 
## List of 3
## $ : logi NA
## $ : int 2
## $ : int 3

c(a, NA*1) |> str() #logical NAs are ok but numerical ones are not? seems very weird....
## Error in `vec_c()`:
## ! Can't combine `..1` <vecreprex> and `..2` <double>.

see also tidyfun/tf#5

@fabian-s
Copy link
Author

sorry, i misread the docs. It's now clear to me that this is actually the expected behavior for c and that vec_c in contrast does what it should.

if any vctrs developers read this, an important Q the docs could maybe answer more explicitly is how to make sure that vec_c is used for concatenation instead of c as often as possible...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant