r-lib / vctrs

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

ptype2 howto shouldn't advise `stop_incompatible_type()` #1731

Open lionel- opened 1 year ago

lionel- commented 1 year ago

In https://vctrs.r-lib.org/reference/howto-faq-coercion.html

Should recommend vec_default_ptype2() instead.

DavisVaughan commented 1 year ago

Does this include stop_incompatible_cast()? Because I feel like being able to call that with custom details is pretty useful https://github.com/DavisVaughan/int64/blob/0922226847a3eec5e4b5887490c8c82b8751a0e5/R/cast.R#L36-L41

lionel- commented 1 year ago

yes I think so. The default method is where we implement all the special behaviour. Maybe we could pass details to stop_incompatible_cast()?

DavisVaughan commented 1 year ago

Why do I want the special behavior though? I'm confident that I want a cast/type error and was trying to directly throw a vctrs compatible one

Calling vec_default_cast() seems less readable because it seems to imply that there is a way that that cast could actually work

lionel- commented 1 year ago

yes it can indeed actually work if someone overrides the method. For this to work, coercion methods should return the result of the default method instead of failing.

DavisVaughan commented 1 year ago

For future us:

someone overrides the method

is referring to utilizing a restart, like https://github.com/r-lib/vctrs/pull/1719