From 0cfc8bb6e1c6cc946cc1deef2adbfe6a9252670b Mon Sep 17 00:00:00 2001 From: AnaNiculescu36 Date: Fri, 6 Dec 2019 12:33:59 +0200 Subject: [PATCH] Updated style guide based on Clockit-Reporting feedback --- style_guide.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/style_guide.md b/style_guide.md index b43fec4..f372098 100644 --- a/style_guide.md +++ b/style_guide.md @@ -50,3 +50,54 @@ Below are more specific guidelines + *preference for singular* + use singular for dataframes, SQL tables, ORM classes + use plural for vectors, e.g., `customer_names` + +## More style advices + +- Note the updated `.Rproj` options: do not save / load data; save history +- Indent 4 space throughout (same for Python and SQL) + + check Global, Project options, then modify each file as needed + + when 4 spaces throughout, restart RStudio +- All files must end with an empty line + + check Global, Project options, then modify each file as needed +- Do make use of code diagnostic Options> Code> Diagnostic> check all) + + fix formatting as needed +- The first line of the file is one line docstring, same as in Python (what is the file about) + + please update all file +- Third line: `# !diagnostics suppress=` for constants +- Fourth, etc. line `# !diagnostics suppress=` for functions +- Once the global constants are read, DO NOT modify them ever + + why: image a multi-user shiny app where each user modifies the global constants + + DB pools work because they are the same for all users + + `.USER_EMAIL` does not work; we need session dependent reactives +- Two spaces between functions or between observers +- There should not be three empty lines anywhere +- (preferable) Empty first line in function (after the title) +- (preferable) Empty before the returned result in a function or event reactive +- Functions and event reactives should always indicate what they return, even if it is `NULL` + + `df <- ... }` works, but not recommended, it needs to end with `df}` +- If using non-starndard evaluation, e.g. `select(df, col1)` in a function, at the begining of the +function add `col1 <- NULL` + + this stops CRAN checker from complaining that `col1` is not found + + resolves ambiguity about `col1` and very likely to result in an error in dplyr if `col1` is missing +- When calling a function, start a new line after `(` as in the duck video +- When defining a function, keep the first arg on the first line, second arg on the second line + + OK to keep everything on one line if 2-3 args + + why: makes each arg standout; extra indentation helps to note the function definition +``` +my_function <- function( + arg1, arg2, arg3 = FALSE, arg4 = NULL) { +``` +becomes +``` +my_function <- function(arg1, + arg2, + arg3 = FALSE, + arg4 = NULL) { +``` +- On each row, close as many parantes as you open in a few rows above +- (preferable) When calling a function, if the arguments span several rows: + + name the arguments + + one argument per line + + the closing paranthesis should be on a new line (preferable, where it helps) +- Use one empty line inside functions to separate code sections + + code comments also help visually + offer guidance