- Functions should be all lower case with underscores separating words
my_function = function { ...
- Variable names should be broken with underscores and prefixed with a data type signifier
str_a_long_name
- Constants should be in all caps
A_CONSTANT
- Underscores are used as most OO languages reserve
.for properties - Use
=for assignment as opposed to<-, in contridiction to all otherRstandards. It's fewer keystroks and there's only really a distinction for legacy reasons, and global assignment in function calls. If writing a package to be released onCRAN,devtoolsoffers a function to replace assignment=s with<-anyway. - When writing packages for release on
CRAN, never uselibrarycalls. Explicitly use::instead - Use spaces between parameters
my_function(a = "foo", b = "bar")
- Shiny server and UI functions should follow best practices found here
- Shiny server and UI functions should be in title case
MyServerFunction, coupled withMyServerFunctionUI
- Modularised code should be stored in a library in seperate files with the filename as the name of the function
MyServerFunction.RcontainsMyServerFunction = function(input, output, ...)
- Shiny server and UI functions should be in title case
- Comments should be placed above code, or two spaces after inline code. A single space should follow the hash before the comment
x = "hi"<two spaces># example comment(GitHub markdown trims whitespace)
- In unit testing it is nessesery to mock functions called by the unit you are testing. To aviod confusion, but make it clear which funtion is being mocked use:
- A the function
function_to_mockis mocked by functionFuntionToMock.
- A the function
dt_- data.tablesdf_- data.framesstr_- vectorised strings<none>- vectorised integers (Not sure about this... might be useful to have something)n_- counts, should be vector of length1ptn_- regex patternsls_- list
get_-SELECTqueriesq_- all other queriesqr_- query requests