Code indentation in R

Even if the structure of the R language foresees particular delimiters for some program blocks, it is still useful, the indentation of the code in R, for the relative identification.

In this regard, it should be recalled that the code indentation refers to the technique used in programming through which program blocks are highlighted by inserting a certain amount of empty space at the beginning of a line of text, with the aim of increasing readability.

Although, as already mentioned, R provides appropriate delimiters for some language structures, we will use the same indentation to indicate the nested blocks; in this regard it is possible to use both a tabulation and an arbitrary number of white spaces.

In using this technique it is necessary to remember simple recommendations:

  • the number of spaces to use is variable;
  • all instructions in the program block must have the same number of indentation spaces.

In this context we will use the convention that provides for the exclusive use of two spacesĀ o identify a new block and to leave out the use of the tab.

Leave a Reply

Your email address will not be published. Required fields are marked *