-
Notifications
You must be signed in to change notification settings - Fork 4
Programming style
Marc Choisy edited this page Aug 20, 2019
·
1 revision
In order to ease the reading of every body's code, please all use this style.
Below I list important points:
- Do not use
return()
calls, unless necessary. By default, any function returns the last instance of its body. Thus,
f <- function(...) {
...
...
return(x)
}
is equivalent to
f <- function(...) {
...
...
x
}
The second option is preferred because it's faster to run (explicitly including return()
adds an extra function call).
- Do not use assignations on the last lines of functions, for the same reason as for the point above. You would use an assignation only if you want the output to be invisible. Indeed,
f <- function() {
a <- 5
}
is equivalent to
f <- function() {
invisible(5)
}