PyCharm 2019.3 Help

Build R packages

With the R plugin for PyCharm, you can build your own R packages. The plugin provides you with the dedicated project type and handy UI tools to build, check, and test your sources.

  1. To create a project, do one of the following:

    • From the main menu, choose File | New Project

    • On the Welcome screen, click Create New Project

  2. In the New Project dialog, select R Package from the available project types.

    Create a new R package
  3. Specify the following parameters:

    • Location: the project directory name. This name is used to create a package title and construct filenames for all sources in the package.

    • Project interpreter: the project interpreter. Expand the Project interpreter area and click New project interpreter next to the Base interpreter field. In the file system, select the R executable file. A sample path to the R executable can be /usr/local/bin/R on macOS or C:\Program Files\R\R-3.6.1\bin\R.exe on Windows.

    • Chosen package manager: the primary tools for building R packages in the project. Expand More settings and select a package manager from the list: Packrat, Rcpp, RcppArmadillo, RcppEigen, or Devtools. If you leave this setting unchanged, the default package managed will be used.

    Click OK to complete the task.

  4. Expand the project content root in the Project tool window. The plugin has created all the required directories and template files.

    Default structure of an R package

  5. Modify the source files and add all the required details according to the Writing R Extensions recommendations.

    • man: the directory that should contain documentation files for the objects in the package in R documentation (*.Rd) format.

    • R: the directory that contains only R code files.

    • DESCRIPTION: the file that contains basic information about the package in the specific format.

    • NAMESPACE: the file that can contain one or more useDynLib directives which allows shared objects that need to be loaded.

    • Read-and-delete-me: the package build instruction.

    Optionally, you can create the src directory if you have any C, C++, or Fortran sources.

  6. When all source files are added, you're ready to install and reload your package. In the Build tab of the R Tools window, click Install and reload.

    Building a package

    Once this done, the tarball file is create and the package is available for your own use.

  7. To check if your package passes the R CMD check and can be uploaded to cran, click Check the package.

    If case of any reported errors or warnings, click Test the package and test the package.

  8. You can tune the build options. Click Build options and deselect or keep selected the following checkboxes:

    Build options

    Each options is selected by default and represents a particular command-line option. Hover over a checkbox to see the corresponding option.

Last modified: 2 April 2020