README.md

RTypeInference

RTypeInference provides functions to infer the types of variables in R code.

A "type" is a set of values that have common representation (in memory) and behavior.

Types are useful for error detection. For instance, dividing one string by another, "hi" / "bye" does not make sense because division is not defined for strings. This is an example of a type error. Catching type errors is so important that many languages require programmers to specify a type whenever they define a variable. Type errors can be detected before the code runs if all the types are known.

In contrast, R does not require programmers to specify a type when they define a variable. Instead, R detects type errors at run-time as they occur. The drawback is that some type errors may go unnoticed until long after code is put into use.

Types are also useful for optimization and documentation of code.

This package can determine the types of many variables in R code even when the types are not specified. The idea is to take advantage of knowledge we have about functions that are built into the language. For example, we know that the length() function always returns an integer, so if we see a definition y = length(x) then we know y must be an integer (regardless of the value of x).

RTypeInference uses a modified Damas-Milner type system for inference. Code analysis tools are provided by rstatic and algebraic data types are provided by typesys. In the future this package may also accept type annotations from the types package where types cannot be inferred.

Installation

RTypeInference is unstable and under active development, so it's not yet available on CRAN. To install, open an R prompt and run:

install.packages("devtools")

devtools::install_github("duncantl/RTypeInference")


duncantl/RTypeInference documentation built on Jan. 16, 2021, 12:30 a.m.