flir is a tool for detecting and rewriting patterns in R source code. Although originally developed as an alternative to conventional R linters, it has evolved into a more general code refactoring utility that can recognise specified expressions and replace them with alternative forms.
The software includes built-in rules for identifying questionable or inefficient coding patterns. For example, it can recommend replacing any(is.na(x)) with anyNA(x), or using anyDuplicated() instead of constructing a logical vector with duplicated() and applying any(). These transformations can make source code more concise or avoid unnecessary computation.
flir provides separate functions for identifying violations and applying corrections. The lint() function examines source files and reports matching patterns, while fix() applies replacement rules where they are defined. Similar functions work directly with code supplied as text, making it possible to experiment with transformations without modifying existing files.
A particularly useful capability is support for custom rules. Developers can define patterns associated with coding conventions, API migrations or project-specific refactoring requirements. Instead of manually editing every matching expression, they can apply the same transformation across a collection of source files.
The package uses astgrepr, which builds on ast-grep, to match source code structures rather than relying exclusively on simple text substitutions. This makes it suitable for transformations involving the syntax of expressions and function calls.
An optional setup function creates a project directory containing rules and a cache. Developers can modify the supplied rules, add their own and benefit from faster subsequent analysis runs.
The developer now concentrates primarily on Jarl for new linting functionality. flir remains useful where configurable code transformation is more important than access to a rapidly expanding collection of conventional linting rules.
This is free and open source software.
Key Features
- Detects specified patterns in R source code.
- Built-in rules for questionable and inefficient coding constructs.
- Automatically rewrites code when replacement rules are available.
- Supports custom pattern-matching and transformation rules.
- Analyses source files, directories and complete packages.
- Can examine and transform R code supplied directly as text.
- Syntax-aware matching through astgrepr and ast-grep.
- Optional project configuration and caching.
- Useful for repetitive refactoring and coding convention changes.
- Cross-platform support – runs on Linux, macOS, and Windows.
Website: github.com/etiennebacher/flir
Support:
Developer: flir authors
License: MIT License
flir is written in R. Learn R with our recommended free books and free tutorials.
Related Software
| R Linters | |
|---|---|
| lintr | Provides static code analysis for R |
| jarl | Fast linter for R |
| flir | Parse and rewrite R code |
| flowR | Sophisticated, static dataflow analyzer |
| checkglobals | R package that performs static analysis of R source code dependencies |
| scilintr | Collection of scientific linting tools |
Read our verdict in the software roundup.
LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more. Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion. Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README. |


Please read our Comment Policy before commenting.