Edit R files
When you have created and configured an R project in PyCharm, you can start editing the default main.R file. However, you can add more .R and .rmd files to your project.
Add new R and R Markdown files to the project
Do one of the following:
Right-click the target directory in the Project tool window, and select New from the context menu.
Select R Script or RMarkdown file.
In the dialog that opens, type a filename. For a RMarkdown file specify its type: document, notebook, presentation, or Shiny (interactive markdown).
A new file has the .R () or .rmd extension ().
PyCharm enables code assistance to facilitate editing and validating R code.
Coding style. Open the code style settings to the preview the default options and modify them according to your preferences. Press Ctrl+Alt+S and go to , then inspect the settings:
Modify any settings if needed. For example, alter the alignment of the assignment operators or comments:
Code completion helps you complete the names of classes, functions, and variables. Start typing the name of the code construct, and the suggestion list appears.
By default, PyCharm provides case-insensitive code completion. To disable it or alter its behavior, clear the Match case checkbox in the project settings ( ).
Code inspections detect and correct various problems in your R script.
As soon as the IDE finds a way to improve your code, it displays a yellow bulb icon in the editor next to the current line. By clicking this icon, you can view intention actions available in the current context. Intention actions cover a wide range of situations from warnings to optimization suggestions.
Quick fixes allow you to resolve a detected problem in one click. A red bulb with an exclamation mark indicates the problematic code and prompts you to select an associated fix. Click the bulb icon or press Alt+Enter to open the list of the fixes.
With the quick fixes for missing import statements you don't need to manually add every single R package to your project. You can just select the Install all missing packages in file option and PyCharm automatically installs all the packages required for your R script.
Hinting allows you to quickly grasp the structure of the code construct and required types of parameters. Place the caret at any function and press Ctrl+P to preview information about its parameters.
By default, PyCharm shows the inlay hints for the R language. You can right-click any inlay element and configure this behavior.
You can disable hints or specify more configuration options in the project.
You can restrict or limit the parameter hints by adding some construct patterns to the black list. Click the Black list link and type one of the shown patterns in the field. Then click OK to save the changes.
In some R functions, the return statement can be omitted. Still, you can configure the function syntax to show the implicit
NULLresult. You can also specify the minimal number of result statements to show the return value hints.
PyCharm automatically saves changes that you make in your files. Saving is triggered by various events, such as compiling, running, debugging, performing version control operations, closing a file or a project, or quitting the IDE. Most of the actual events are predefined and cannot be configured, but you can be sure that changes will not be lost as you work.
With the R plugin you can quickly preview reference documentation for a particular variable, class, type, or argument. In the R console, type
?and the code element name, for example,
?barplot. The corresponding reference documentation appears in the Documentation tab of the R Tools window.
To preview documentation for a particular package, click its name in the Package column of the Packages tab of the R Tools window.
When editing an R file, you can quickly navigate through your code and jump to a particular variable or function. You can open the Structure tool window or select the target variable in the editor and click the corresponding breadcrumb element to open the structure popup window.