Idiomatic R coding standards for statistical analysis. Use when writing R functions, using tidyverse/data.table, or structuring analysis scripts.
library() only: Never require() in scripts. Use library() at script top.pkg::fun() to avoid namespace collisions. Always for infrequent calls.for loop on data, you're probably doing it wrong.apply family: sapply, vapply, lapply, mapply for list/matrix operations.purrr: map(), map_dbl(), map_dfr() for type-stable functional programming.data.table: Use [i, j, by] syntax for grouped operations on large datasets.Vectorize(): Wrap scalar functions for vector input when needed.return().<<- in functions. Return values instead.purrr::safely(): Wrap functions that may fail to capture errors without stopping.tidyverse Guide)snake_case for all names. PascalCase only for R6 classes.<- for assignment. Reserve = for function arguments only.<-, after #. No space before ( in function calls.{ on same line, } on own line. Always use braces, even for one-liners.styler::style_file() and lintr::lint().rm(large_df); gc() after processing.data.table::fread() with select for column subsetting..RData avoidance: Never save/load .RData. Use explicit saveRDS()/readRDS().