6.2 Optional conventions to organise functions
- File names should be meaningful and convey which functions are defined within
- Avoid having:
- One file per function
- All functions in the same file
- A single .R file can have:
- A main function and its supporting helpers like the tidyr::separate function
- A family of related functions like the tidyr::hoist and tidyr::unnest functions
- A very large function with lots of documentation like the tidyr::uncount function.
- For small helper functions used in functions across different files are typically stored in
R/utils.R
by convention (e.g spotifyr/R/utils.R)
If its hard to predict in which file a function lives, it’s time to separate your functions into more files.