Skip to main content
Version: Next

The Vapour Guide

Vapour is a typed language that transpiles to R. You write .vp files, Vapour checks them, and then turns them into plain R code that runs anywhere R runs.

This guide teaches the language from the ground up. Read the chapters in order: each one builds on the previous one, and every example can be copied into a file and run.

Looking for the exact rules?

This guide explains how to use Vapour, with plenty of examples. The specification states the same rules briefly and precisely, for when you need a definitive answer.

Why Vapour?​

Code is read far more often than it is written. When you add up the time spent on a project, very little of it goes into typing the code. Most of it goes into reading code, looking for bugs, and changing code without breaking it.

Vapour makes you write a little more code so you can read it faster, find bugs sooner, refactor without fear, and get fewer errors at run time.

In practice this means three things:

  1. Everything is declared. Variables are declared with let or const and have a type. Functions say what they accept and what they return.
  2. Vapour checks your code before it runs. It catches values of the wrong type, misspelled variables, missing arguments, unexpected NULLs, and more.
  3. The output is just R. If you ever stop using Vapour, the R code it generated is still there and readable. Nothing locks you in.

How it works​

Vapour adds a build step between the code you write and the code that runs:

script.vp  ──▶  vapour checks it  ──▶  script.R  ──▶  R runs it

The check step is where Vapour is useful. It reports problems as diagnostics (errors, warnings, and hints), and refuses to produce R code when it finds an error.

With an editor plugin you see the same diagnostics while you type, before you run anything.

What you need​

  • R, Vapour calls R to know about base R functions.
  • The vapour command line tool, see install.
  • Optionally, an editor plugin for syntax highlighting and live diagnostics.

This guide assumes you know some R. Each example shows the Vapour code next to the R code it produces, so you can always see what Vapour does.

What's in this guide​

The basics

  1. Your first program: write, check, run, and transpile a script.
  2. Variables: let, const, assignment, and values.
  3. Types: the built-in types and how Vapour checks them.
  4. Control flow: vectors, operators, conditions, and loops.
  5. Functions: declaring, calling, and passing functions.

Going further

  1. Custom types: objects, structs, data frames, and more.
  2. Methods: S3 methods, generics, and classes.
  3. Packages: writing R packages in Vapour and sharing types.
  4. Diagnostics: every check Vapour runs.

Examples

Complete programs that put it all together: a basic script, callbacks, S3 methods, and a Shiny app.