Air
R formatter and language server
| Type | object |
|---|---|
| File match |
air.toml
.air.toml
|
| Schema URL | https://catalog.lintel.tools/schemas/schemastore/air/latest.json |
| Source | https://github.com/posit-dev/air/releases/latest/download/air.schema.json |
Validate with Lintel
npx @lintel/lintel check
Configuration for Air
Properties
Definitions
Options to configure code formatting.
Air automatically excludes a default set of folders and files. If this option is
set to false, these files will be formatted as well.
The default set of excluded patterns are:
.git/renv/revdep/cpp11.RRcppExports.Rextendr-wrappers.Rimport-standalone-*.R
Air automatically formats a default set of calls as tables. You can
disable these defaults by setting this option to false. The default
set currently includes:
tribble()from tibblefcase()from data.table
By default, Air will refuse to format files matched by patterns listed in
default-exclude. Use this option to supply an additional list of exclude
patterns.
Exclude patterns are modeled after what you can provide in a
.gitignore, and are resolved relative to the
parent directory that your air.toml is contained within. For example, if your
air.toml was located at root/air.toml, then:
-
file.Rexcludes a file namedfile.Rlocated anywhere belowroot/. This is equivalent to**/file.R. -
folder/excludes a directory namedfolder(and all of its children) located anywhere belowroot/. You can also just usefolder, but this would technically also match a file namedfolder, so the trailing slash is preferred when targeting directories. This is equivalent to**/folder/. -
/file.Rexcludes a file namedfile.Rlocated atroot/file.R. -
/folder/excludes a directory namedfolder(and all of its children) located atroot/folder/. -
file-*.Rexcludes R files named likefile-this.Randfile-that.Rlocated anywhere belowroot/. -
folder/*.Rexcludes all R files located atroot/folder/. Note that R files in directories underfolder/are not excluded in this case (such asroot/folder/subfolder/file.R). -
folder/**/*.Rexcludes all R files located anywhere belowroot/folder/. -
**/folder/*.Rexcludes all R files located directly inside afolder/directory, where thefolder/directory itself can /// appear anywhere.
See the full .gitignore documentation for all of the patterns you can provide.
indent-style = "space" (default):
fn <- function() {
# Spaces indent `cat()`
cat("Hello")
}
indent-style = "tab":
fn <- function() {
# A tab `\t` indents `cat()`
cat("Hello")
}
Air defaults to spaces due to the overwhelming amount of existing R code written in this style, but consider using tabs for new projects to improve accessibility.
See indent-width to configure the number of spaces per indentation and the tab
width.
The value must be greater than or equal to 1 and less than or equal to 24. The
default value is 2.
Used by the formatter to determine the visual width of a tab.
This option changes the number of spaces the formatter inserts when using
indent-style = "space". It also represents the width of a tab when indent-style = "tab" for the purposes of computing the line-width.
-
auto: The newline style is detected automatically on a file per file basis. Files with mixed line endings will be converted to the first detected line ending. Defaults to\nfor files that contain no line endings. -
lf: Line endings will be converted to\n. The default line ending on Unix. -
crlf: Line endings will be converted to\r\n. The default line ending on Windows. -
native: Line endings will be converted to\non Unix and\r\non Windows.
The value must be greater than or equal to 1 and less than or equal to 320.
While the formatter will attempt to format lines such that they remain within the
line-width, it isn't a hard upper bound, and formatted lines may exceed the
line-width.
Air respects a small set of persistent line breaks as an indication that certain
function calls or function signatures should be left expanded. If this option
is set to false, persistent line breaks are ignored.
It may be preferable to ignore persistent line breaks if you prefer that line-width
should be the only value that influences line breaks.
Air typically formats every function call it comes across. To skip formatting of
a single one-off function call, you can use a # fmt: skip comment. However, if
you know of particular functions that you use a lot that are part of a custom
domain specific language that doesn't follow conventional formatting rules, you
can entirely opt out of formatting for those functions by providing them here.
For example, using skip = ["graph_from_literal"] would automatically skip
formatting of:
igraph::graph_from_literal(Alice +--+ Bob)
Some function calls are meant to be formatted as tables, rather than being
formatted in a flat or expanded layout. For a single one-off function call,
you can use a # fmt: table comment to request a table layout. For function
calls that you use a lot, use this setting to add them to a list of function
calls that are automatically formatted as tables without requiring a
# fmt: table comment.
For example, using table = ["my_table"] would automatically format calls
to my_table() in a table layout.
See default-table for the list of function calls that are automatically
formatted as tables by default.