The R Style Guide describes the rdev style conventions, along with automated checks (styler and lintr). The rdev R Style Guide incorporates both the Tidyverse Style Guide and Google’s R Style Guide.
rdev uses a mix of Google and tidyverse conventions.
rdev typically uses implicit returns unless needed for flow control or to construct a specific return structure.
discouraged, instead using
:: in functions defined in
R/. An exception is infix functions (
which are always imported, using roxygen
Within R Notebooks, use of
library() is encouraged for
rdev package documentation lives in
Additionally, use of base R is encouraged within functions defined in
R/ (to control dependencies), where tidyverse R is
encouraged within notebooks for readability.
R Markdown documents should generally wrap at the same width as code, with exceptions for the R Notebook ‘description line’ (the first non-blank line in the body), and long hyperlinks.
The rdev package implements styler using the styler defaults,
with permanent caching enabled
options(styler.cache_root = "styler-perm")). The
style_all() function applies the tidyverse style to all R
Rnw) in the package directory structure.
rdev uses an opinionated lintr
linters: linters_with_tags( tags = NULL, extraction_operator_linter = NULL, implicit_integer_linter = NULL, line_length_linter(100), missing_package_linter = NULL, namespace_linter = NULL, nonportable_path_linter = NULL, todo_comment_linter = NULL, undesirable_function_linter( within(all_undesirable_functions, rm(ifelse, library, require)) ), undesirable_operator_linter(all_undesirable_operators), unneeded_concatenation_linter(allow_single_expression = FALSE), unused_import_linter( except_packages = c("bit64", "data.table", "tidyverse", pkgload::pkg_name(".")) ) )
These settings were deliberately chosen to meet specific goals:
Use all linters
This selects all linters, including the new Google linters. By selecting all linters, not just the defaults, this forces evaluation of new linters as they are added to lintr. Specific linters are disabled or configured per rdev style.
Allow $ extraction operator
The extraction operator linter enforces use of
$ is intended for interactive use and
supports partial mapping, it is safer to use
$ is common practice, including within the lintr
code, and leads to more readable code.
Allow implicit integers
The implicit integer linter checks that integers are explicitly typed
using the form
1L. Again, while this is safer, implicit
integers are common practice, including in the output of
Set line length
A line length of 100 is a reasonable width when working in the RStudio IDE on a laptop.
Use renv for missing packages
The missing package linter and the namespace linter both check for
packages referenced in code that are not installed. rdev uses renv to manage packages,
which does a better job of detecting missing packages, including not
complaining when the current package (
".") is not
Allow non-portable paths
The non-portable path linter generates too many false positives, including calls to fs, which essentially makes UNIX-style paths portable across operating systems.
Allow TODO comments
rdev conventions encourage use of
# TODO comments as a
convenient way of identifying needed or planned updates inline.
Disallow almost all undesirable functions and operators
undesirable_function_linter( within(all_undesirable_functions, rm(ifelse, library, require)) ), undesirable_operator_linter(all_undesirable_operators),
Enable all undesirable functions and operators, not just the
defaults, except for
ifelse() which is more succinct than
require(). Use of
library() within R Markdown
documents is an appropriate and common practice, although neither should
be used within package code.
Enforce strict unneeded concatenation
Enforce the stricter version of the unneeded concatenation linter.