Diagnostics
Vapour checks your code before transpiling it, and reports what it finds as diagnostics. You see them in your editor through the LSP, and in the terminal when you use the CLI. This chapter explains how to read them, and lists every check.
Reading a diagnostic
In the terminal, each diagnostic is one line:
[SEVERITY] file:line:column message
For example:
[WARN] script.vp:6:23 `n` might be missing
✓ files successfully transpiled!
This says: in script.vp, line 6, column 23, the argument n might
be missing. It's a warning, so the file was still transpiled.
Severities
| Severity | Meaning | Stops transpilation |
|---|---|---|
ERROR | The code is invalid, or will fail | Yes |
WARN | The code will probably fail | No |
INFO | Something is likely a mistake | No |
HINT | The code could be improved | No |
Only errors stop transpilation. Don't ignore the rest: a warning usually means an error at run time.
To only run the checks, without transpiling, use -check-only
(see CLI). You can choose which severities your
editor shows, see customise.
Errors
Declarations
| Check | Learn more |
|---|---|
| variable is already declared | variables |
| function or type is already defined | functions |
| functions and types cannot share a name | functions |
| function shares its name with a base R function | functions |
| type is not declared | custom types |
| constant without a value, or with several types | variables |
| assigning to a constant | variables |
assigning to a parent variable (<-) that does not exist | variables |
Types
| Check | Learn more |
|---|---|
assigning a value of the wrong type, including nested attributes, e.g.: a$b$c | types |
| loop variable whose type does not match the elements | control flow |
non-numeric value in a range, e.g.: "a"..3 | control flow |
returning a value of the wrong type, or not returning (except null functions) | functions |
vector mixing types, e.g.: (1, "a") | types |
using $ on a vector type | control flow |
| unknown attribute, or attribute of the wrong type | custom types |
| looping over a type that cannot be iterated | custom types |
break or next outside of a loop | control flow |
Functions and methods
| Check | Learn more |
|---|---|
| argument of the wrong type | functions |
| unknown named argument, or too many arguments | functions |
| duplicated argument | functions |
method on any without @generic or @default | methods |
| callback with the wrong arguments or return type | functions |
| the same method is defined twice on a type | methods |
Custom types
| Check | Learn more |
|---|---|
object, struct, and environment attributes must be named | custom types |
struct expects one unnamed first argument | custom types |
list, factor, and vectors expect unnamed arguments | custom types |
unexpected decorator argument, e.g.: @matrix(foo = 1) | custom types |
Warnings
| Check | Learn more |
|---|---|
variable not found, e.g.: print(x) where x is not declared | variables |
| argument might be missing | functions |
Info
| Check | Learn more |
|---|---|
| variable or type is never used | variables |
comparison between types that are not comparable, e.g.: "a" > 1 | control flow |
Hints
| Check | Learn more |
|---|---|
| package is not installed | control flow |
function is not exported by the package, e.g.: dplyr::foo() | control flow |
use of library() or require(), prefer pkg::fn() | control flow |