Any plans for mypy equivalent for R?

Python's typing package is a boon for module development. When developing R packages I often wish for some form of static type checking ala mypy. Does anyone know of any plans to introduce something similar for R? I have caught numerous coding errors and am able to clearly document function contracts using the gradual typing enabled by mypy.

Something similar for R would be hugely beneficial for package development and documentation. I realize this would be a monumental undertaking and am just curious if it has been discussed by folks in r-devel or Rstudio (or elsewhere) as a desired feature.


There are some packages that implement strong typing in R:

And you might also be interested in these related packages:

  • zatonovo/lambda.r - Provides a syntax for functional programming, including a type system (CRAN)
  • r-lib/vctrs - This package doesn't introduce a type system, but it tries to make the existing types more stable (e.g. make the outcome more predictable when combining vectors with c()) (CRAN)

Thanks for the links. Looks like these implement runtime checks to enforce the typing. It likely doesn't exist, but I am really wishing for a static type checker that can be run with a linting step ala mypy. I'm not sure R's syntax can support that, though. Maybe with something like python's typing for python 2 that relied on comments.

1 Like

I have thought about it, and have a simple package on CRAN {types} showing how you can add types with ?

But the bulk of the work would be using these types of annotations to do static analysis, or doing other things like adding optional type checks to the code. was an exploration along these lines.

Aviral Goel is also doing ongoing research at Northeastern on type annotations for R, e.g. with his project.

But the bottom line is none of these projects is anywhere close to mypy and it would take a considerable investment before they provide much of a productivity boost.

There have been no serious talks at RStudio I am aware of to provide a mypy equivalent, but if more community members express interest in gradual typing maybe that would change.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.