CellNOpt Documentation Center (CNODocs) (0.1.6)

4.1. R code conventions

There are just a few conventions that should be taken into account when developping/changing CellNOptR and add-on package such as CNORfuzzy, CNORode...

Note

do not change the layout of a file except if you think it does not fulfill the following conventions.

4.1.1. Function naming convention

  1. acronyms should be all in big caps (e.g, NONC, MIDAS, SIF, PDF, CNO).
  2. functions must start with small caps except if acronym.
  3. If several words make up a function name, each word should start with a big Cap to ease the reading (e.g., compressModel, cutSimList)
  4. a word following an acronym should start with big cap except for CNOlist that is used everywhere with small caps for “list”.
  5. if a number splits 2 words (e.g. sif2graph) then no need for a big cap. The name is clear enough.

Correct:

prep4sim
plotFit
readMIDAS

Incorrect:

prep4SIM
PlotFit
readMidas

4.1.2. Tabulations

Some people uses tabs, some others spaces. We decide to use spaces instead of tabs (4 spaces for 1 tab). This is just an arbitrary convention to avoid mixing both without knowing. Easy to set up in any editor.

Code should look like (not the spaces, the curly brackets:

preprocessing <- function(Model){
    m <- Model
    for (r in 1:length(Model$reacID){
        # do something
    } # end of for loop
} # end of main function

At least not something like:

preprocessing <- function(Model){
m <- Model
for (r in 1:length(Model$reacID){
# do something
} # end of for loop

4.1.3. Function arguments convention

Should follow the same rule as for the naming convention and be consistent over all functions and packages.

Correct:

CNOlist
maxTime
elitism
simList
model

Incorrect:

CNOLIST
MaxTime
Elistism
SimList
Model

4.1.4. Variable name convention

  1. should be lower caps
  2. see function naming convention if acronym is present or variable name made of several words.

Correct:

maxTime, maxtime
simList, simlist
pMutation

Incorrect:

MaxTime
MAXTIME
Pmutation

Ambiguous:

initBstring since B is not a word but an abbreviation. It should be initBitString somehow but this is long. In such case, developer has to make a choice.

4.1.5. 80 characters length

You should try to stick to a maximum length of 80 characters per line. Two reasons:

  1. if you want to print the code, the layout is nicer
  2. more than 80 characters per line systematically is probably because the code is not modular enough
  3. To compare 2 files, it is convenient to open 2 windows side by side hence the need for reasonable width.