You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Good
fit_models.R
utility_functions.md
# Bad
foo.r
stuff.MD
Object names
# Good
day_oneday_1
# Bad
first_day_of_the_monthDayOnedayonedjm1
# Bad
T <- FALSE
c <- 10mean <- function(x) sum(x)
Spacing
# Good
average <- mean(feet / 12 + inches, na.rm = TRUE)
# Bad
average<-mean(feet/12+inches,na.rm=TRUE)
# Good
x <- 1:10base::get
# Bad
x <- 1 : 10base :: get
# Good
if (debug) do(x)
plot(x, y)
# Bad
if(debug)do(x)
plot (x, y)
# Good
list(
total = a + b + c,
mean = (a + b + c) / n
)
# Good
if (debug) do(x)
diamonds[5, ]
# Bad
if ( debug ) do(x) # No spaces around debug
x[1,] # Needs a space after the comma
x[1 ,] # Space goes after comma not before
Curly braces
# Good
if (y < 0 && debug) {
message("Y is negative")
}
if (y == 0) {
log(x)
} else {
y ^ x
}
# Bad
if (y < 0 && debug)
message("Y is negative")
if (y == 0) {
log(x)
}
else {
y ^ x
}
# Good
if (y < 0 && debug) message("Y is negative")
Indentation
# Good
long_function_name <- function(a = "a long argument",
b = "another argument",
c = "another long argument") {
# As usual code is indented by two spaces.
}