Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robustness linters #48

4 of 11 tasks
jimhester opened this issue Feb 5, 2015 · 1 comment
4 of 11 tasks

Robustness linters #48

jimhester opened this issue Feb 5, 2015 · 1 comment
feature a feature request or enhancement


Copy link

jimhester commented Feb 5, 2015

Suggestions from @hadley

  • Require drop = FALSE whenever [ is used with two or more args
  • Require na.rm argument for any function that has it (to force you to
    think about missing values during development)
  • Don't use of require()/library() inside a function
  • Don't change global state: setwd(), options(), par() etc. Could
    have next package robustr that contained alternatives (i.e. the with_*
    functions from devtools)
  • Always turn partial matching warning options on (not really code
    linting, but related)
  • Avoid functions that use NSE (with(), subset(), transform() etc)
  • Avoid functions that return different types of output (e.g. sapply())
  • TRUE and FALSE instead of T and F.
  • return() calls at the end of functions (result of last statement is always returned, so the explicit return() is redundant (and also slower as it requires an additional function call).
  • use of 1:length(x) in for loops (dangerous if length(x) can be 0) as 1:0 returns c(1, 0), should use seq_len(length(x)) instead.
  • Iterative appending to vectors within loops rather than pre-allocation the vectors and filling. (the former is quadratic in time complexity, as R has to keep re-sizing the vector on every assignment.
# bad
for (i in seq_len(10)) {
  x <- c(x, i)

# good
x <- integer(10)
for (i in seq_len(10)) {
  x[i] <- i
Copy link

fangly commented Mar 13, 2017

The following items have been implemented recently:

  • 1:x usages are caught by seq_linter()
  • T_and_F_symbol_linter catches "T" and "F" instead of TRUE and FALSE.
  • setwd(), options(), par(), sapply are linted by undesirable_function_linter() using the functions listed by default_undesirable_functions(). Additional functions to lint can easily be added.
  • same thing for require, library, although all uses are detected, not just within a function

@jimhester jimhester added feature a feature request or enhancement and removed enhancement labels May 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
feature a feature request or enhancement
None yet

No branches or pull requests

2 participants