vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

ptype2 howto shouldn't advise `stop_incompatible_type()`

Open lionel- opened this issue 3 years ago • 5 comments

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

Should recommend vec_default_ptype2() instead.

lionel- avatar Oct 19 '22 11:10 lionel-

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

DavisVaughan avatar Oct 31 '22 13:10 DavisVaughan

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

lionel- avatar Oct 31 '22 13:10 lionel-

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

DavisVaughan avatar Oct 31 '22 13:10 DavisVaughan

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.

lionel- avatar Oct 31 '22 14:10 lionel-

For future us:

someone overrides the method

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

DavisVaughan avatar Oct 31 '22 17:10 DavisVaughan