Defensive R Programming
Dr. Colin Gillespie
Jumping Rivers
Everyone agrees that consistency is key
This may mean changing styles when in different teams!
=
vs ->
x = 5
# or
x <- 5
Everyone agrees you shouldn't mix & match
I prefer the superior =
for assignment but
DataCamp prefers <-
for their courses
So be consistent
Consistent spacing makes code far easier to read
Compare
res<-t.test(x,paired=FALSE)
with
res <- t.test(x, paired = FALSE)
Two widely accepted rules are
x <- 5
x[1, 1]
instead of x[1,1]
Defensive R Programming