PyCharm 2019.3 Help

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

  1. Do one of the following:

    • Right-click the target directory in the Project tool window, and select New from the context menu.

    • Press Alt+Insert

  2. Select R Script or RMarkdown file.

  3. In the dialog that opens, type a filename.

A new file has the .R or .rmd extension and it is marked with the corresponding icon: R file icon.

PyCharm enables code assistance to facilitate editing and validating R code:

  • 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.

    Code completion for R
    Code completion for R
  • Code inspections detect and correct various problems in your R script.

    R inspection: unresolved reference

    As soon as the IDE finds a way to improve your code, it displays a yellow bulb icon 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.

    You can view the full list of available intention actions, and disable actions that you do not need. In the Settings/Preferences dialog Ctrl+Alt+S, go to Editor | Intentions, and search for the R language.

  • Quick fixes allow you to resolve a detected problem in one click. A red bulb with an exclamation mark the Quick-fix icon 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.

    Quick-fix fix for the missing import statement

    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.

  • Auto saving

    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.

  • Quick documentation

    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 tool window.

    Viewing quick documentation for the barplot class

  • 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.

    View the R file structure

Last modified: 10 December 2019