Norms for writing code in the vmTools project.
Lean into the Tidyverse Style Guide when possible, but don’t adhere to it slavishly when common sense dictates otherwise, or where noted below.
“There are only two hard things in Computer Science: cache invalidation and naming things.” - Phil Karlton
get
for a function that
retrieves data, don’t use fetch
in another part of the
project.TRUE/FALSE
, or other common terms. Avoid
abbreviations when naming variables/functions.# ... ----
for the main
header and ## ... ----
for subheaders. All headers should
be 80 characters long.# Load data --------------------------------------------------------------------
## Load reference files --------------------------------------------------------
(
and [
:
Except in data.table
calls, by convention. Avoid hanging
indentation.
# Bad
my_list <- list(name1 = "value1",
name2 = "value2",
name3 = "value3")
# Good
my_list <- list(
name1 = "value1"
, name2 = "value2"
, name3 = "value3"
)
# Better
my_list <- list(
name1 = "value1"
, name2 = "value2"
, name3 = "value3"
# Best
my_list <- list(
name1 = "value1"
, name2 = "value2"
, name3 = "value3"
)
object.method()
syntax - only use when relevant (usually
S3).x
, the first argument should always
be x
./file/path
.NULL
as the default
value, and handle NULL
behavior explicitly in the
function.data
instead of data_df
or
data_tbl
. Types in argument names makes function
maintenance more difficult. If a type needs to change, then the function
argument also needs to change, which breaks backward compatibility.
Handle type-checking explicitly within the function instead.END