R 防御式编程
Dr. Colin Gillespie
Jumping Rivers
类似拼写检查器的工作方式
要使用 lintr
lint() 函数假设有以下代码:
my_bad<-function(x, y) {
x+y
}
保存在文件 code.R 中。
lintr::lint("code.R") 会标出两个问题my_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
R 防御式编程