-
Couldn't load subscription status.
- Fork 194
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
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())
-
TRUEandFALSEinstead ofTandF. -
return()calls at the end of functions (result of last statement is always returned, so the explicitreturn()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) as1:0returnsc(1, 0), should useseq_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
}rentrop
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement