types
Syntax and types
Typed R keeps a syntax that is deliberately close to standard R. Type annotations are added in a lightweight and readable way, designed to integrate naturally with existing R code.
Types can appear:
- in variable declarations,
- in function parameters,
- in function return types,
- in structured data definitions.
The design principle is that typed code should still look like R, with minimal syntactic overhead.
Basic types
Typed R provides explicit basic (primitive) types, which form the foundation of the type system:
- Numeric types (e.g. integers, floating-point numbers)
- Boolean values
- Character strings
- Missing values
These types allow the compiler to detect invalid operations early, such as applying numeric operations to non-numeric values.
Composite types
In addition to basic types, Typed R supports composite types to model more complex data:
- Vectors with guaranteed element types
- Lists with typed elements
- Records (structured objects with named and typed fields)
- Data frames with explicit schemas
Composite types make data structures self-documenting and safer to manipulate, especially in large data-processing pipelines.
Type inference
Typed R features type inference, meaning that explicit type annotations are not always required.
When possible, the compiler automatically infers types based on:
- literal values,
- expressions,
- function bodies,
- usage context.
This allows developers to write concise code while still benefiting from static type checking. Explicit types can be added incrementally where clarity or safety is critical.