HenrikBengtsson / Wishlist-for-R

Features and tweaks to R that I and others would love to see - feel free to add yours!
https://github.com/HenrikBengtsson/Wishlist-for-R/issues
GNU Lesser General Public License v3.0
133 stars 4 forks source link

MEMORY: Protect against coercion ("gradual typing") #53

Open HenrikBengtsson opened 6 years ago

HenrikBengtsson commented 6 years ago

Wish

> x <- integer(10)
> allow_coercion(x) <- FALSE
> x[1] <- 2
Error: Cannot assign value of type 'double' to an object of type 'integer' without coercion.

Ideas

Hmm... I need to think about this one. It might be that this has to be done deep down in core R;

Related

hammer commented 5 years ago

Jan Vitek has given talks on this topic at Directions in Statistical Computing (DSC):

Within Jan's group, aviralg seems to be implementing these ideas in annotatr, contractr, and profilr. He's also making use of PRL-PRG/typeR, which looks nice.

lionel- commented 5 years ago

It's possible to do this with classes. The vctrs package developed a class of vectors with stronger coercion semantics. This is all runtime checking of types though, so a different idea than gradual typing.