Building packages with RStudio

RStudio combines the power of devtools with its GUI, which makes the development of your own packages very easy and manageable with just a few clicks.

To create a new package with RStudio, just click on File | New Project... and select New Directory.

Creating a new package project with RStudio

Then you can select R Package from the upcoming menu:

Creating a new package project with RStudio

Now you have to set the necessary parameters for your R package. These include the type of the package, the package name, the option to create a package based on source files, and to create the package project as a subdirectory of another directory.

Furthermore, you can check the options for creating a Git repository or for using Packrat with your project.

Creating a new package project with RStudio

If you want to create a package just containing R code, you should select the type to be Package. However, if you want to create a package that also uses C++ code, you should choose Package w/ Rcpp as it automatically sets up all necessary dependencies for using the Rcpp package that helps you to access or extend R objects at the deep C++ level.

Creating a new package project with RStudio

After we save our project, RStudio automatically creates the necessary files and the file structures. This includes the folders and the DESCRIPTION and NAMESPACE file.

Looking at the created files

When the package is created, a new file with the name hello.R will be opened in the source pane. This file includes a basic hello world example in R and some useful shortcuts for RStudio when you create a package.

Looking at the created files

The shortcuts for package authoring are: