This is probably one of the more complicated cases to coerce to. Here I'll lay out how I think each of the vector types should be treated.
[x] logical: Same as as.integer (TRUE == 1, FALSE == 0).
[x] integer: (identity)
[x] double: Coerce if no info lost (vctrs::vec_cast() appears to (mostly?) handle this). Remember to test Inf.
[x] character: Coerce if no info lost on round trip (base as.integer("1.1") yields 1, as.character(as.integer("1.1")) yields "1", doesn't match). Round trip might be a general rule.
[x] complex: Round trip appears to work here, too!
[x] raw: For now fail I think, but I may come back to this.
[x] default: Round trip test?
[x] NULLs: NULL (like vec_cast) or integer(0) (base)?
[x] NAs: deal with them.
Make sure it's still fast. For the case without coercion, it should have virtually no overhead. With coercion can be slower but not a lot slower.
This is probably one of the more complicated cases to coerce to. Here I'll lay out how I think each of the vector types should be treated.
vctrs::vec_cast()
appears to (mostly?) handle this). Remember to test Inf.Make sure it's still fast. For the case without coercion, it should have virtually no overhead. With coercion can be slower but not a lot slower.