Open HenrikBengtsson opened 6 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.
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.
Wish
Ideas
Hmm... I need to think about this one. It might be that this has to be done deep down in core R;
tracemem()
will detect it, or more specifically, it'll output text to stdout that carry information/traces of coercions, but I don't see how to capture such output automatically.It's semi doable by
trace()
:ing[
but that is of course not a general solution and it won't detect intermediate coercions occurring internally.trace()
could run a temporarytracemem()
withcapture.output()
upon entering the function, meaning it should be able to detect also intermediate coercions.trace()
cannot be stacked/nested, i.e. using it may introduce unwanted side effects.Coercion in core R takes place in https://github.com/wch/r-source/blob/trunk/src/main/coerce.c
Related