The R / Python Editor is where the code is written in order to execute it in R / Python.
With CTRL+R or CTRL+Enter, the current selection (or the current line if no selection) is executed in R in a .R file, in Python in a .py file. The arrow in the top menu (CTRL+SHIFT+R) executes the whole file.
A right click shows the following options:
- Go to Definition (F12)
- Go to References (SHIFT+F12)
- Run selection or line executes the selection or line, like CTRL+R or CTRL+Enter ;
- Comment / Uncomment selection comments / uncomments the selection ;
- Search in Python / R documentation
- Rename Symbol (F12)
- Change All Occurrences (CTRL+F2) changes all occurrences of the current text at the same time ;
- Format Document (SHIFT+ALT+F)
- Command Palette (F1) opens the command palette with more options.
You also have the following useful shortcuts:
- CTRL+F to search in the code ;
- CTRL+H to replace ;
- CTRL+G to go to a specific line.
The R Editor comes with an autocompletion system with the existing R / Python functions.
- TAB or Enter validates the proposition in the first screenshot above ;
- CTRL + Space opens the description of the proposed function (and autocompletion if closed) in the first screenshot above ;
- CTRL + Space opens the different agruments of the function in the second screenshot above, R only ;
- Echap removes the autocompletion.
For each variable / function defined in the file, it provides it in the autocompletion a cube for a function and with a cobblestone for a variable.
We now go in details how works the autocompletion for each language. Since there is some difference in the standards, we separate it below in two tabs.
The autocompletion system finds any custom function that are defined and any function from packages if
library(mypackage) is written in any opened file, no matter that it is loaded in the R session or not.
When a personal function is written in any opened file, it is proposed as below (same with functions from packages).
The help of the function above is empty. It is possible to fill it, and even to fill the help for each argument of the function and more. This is done with the following syntax.
To do it, as above, write a block comment at the top of the function with its description (which can be on several lines) and a single line for each argument, with the syntax
#' @param argument help. You can also add information about the returned value with
#' @return help or an example with
#' @example help.
Do not leave any empty line between the comment and a function definition, else the comment will not be recognized as the description of the function.