Defensive R Programming
Dr. Colin Gillespie
Jumping Rivers
Similar to how spell checkers work
To use lintr
lint()
functionSuppose I have the following code
my_bad<-function(x, y) {
x+y
}
saved in the file code.R
.
lintr::lint("code.R")
highlights two issuesmy_bad<-function(x,y) {
x+y
}
r[[1]]
tmp.R:1:7: style: Put spaces around all infix operators.
my_bad<-function(x,y) {
~^~~
my_bad <- function()
my_bad<-function(x,y) {
x+y
}
r[[3]]
tmp.R:2:4: style: Put spaces around all infix operators.
x+y
~^~
x + y
Defensive R Programming