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.
To create a project, do one of the following:
Go to
On the Welcome screen, click Create New Project
In the New Project dialog, select R Package from the available project types.
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. Expand the Project interpreter area and click 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.
Expand the project content root in the Project tool window. The plugin has created all the required directories and template files.
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.
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 .
Once this done, the tarball file is create and the package is available for your own use.
To check if your package passes the
R CMD check
and can be uploaded to cran, click .You can tune the build options. Click and deselect or keep selected the following checkboxes:
Each options is selected by default and represents a particular command-line option.
If case of any reported errors or warnings during a package build, click and test the package.
Test a package
Create a test for an R file by one of the following ways:
Click on the R file toolbar.
Select a target R file in the Project tool window, right-click it, and from the context menu, select Create Test File.
A newly added test file will be placed under the test directory in the project root. You can use the same editor icon and context menu to navigate from an R file to its test.
Add some testing code to the newly create test file.
You can run each test individually by calling the Run action in a target test file (the icon on the R file toolbar), or you can run all tests for the package using the corresponding icon in the Build tab of the R Tools window.
Preview the test run results and fix the R code when appropriate.