Package development is a lot easier than you think. Follow the steps below, and you should have no problem.
Basics
Compiling a package
Assuming you have the package in a local folder, and work with RStudio (both recommended)
- Create a new RStudio project in the folder
- Choose the project folder in Tools/Project Options/Build tools. Make sure you also check Roxygen if you want to use Roxygen (see below, recommended)
- Buttons for building the package should now appear in the top right panel of RStudio
For further help or for info how to compile from the console (takes more time) use google.
Creating a new package
- Work with RStudio, makes many things easier (alternative is StatET in eclipse, particular if you also have C/C++ code in your package)
- Follow this article to create a new package
- Enable the package development in tools/project options, and you will see a new menu in Rstudio that allows you to build the package with one click
Adding R code to the package
Simply move your R code to the R folder (if it doesn’t exist, create an R folder directly under the package root)
Documentation
Documentation files for each function are in the man folder. The name must be functionName.Rd.
We won’t even bother explaining how to modify this file, because it doesn’t make sense to write the documentation by hand. Use the Roxygen style for commenting your R functions, and the .Rd files in man will be created automatically.
- Read here about how to work with Roxygen
- The easiest way to do this during package development is to enable tick the Roxygen options in RStudio, project options, and then you can create the man files in the build menu
Advanced topics and further reading
Before you go on with package developments, read this which explains all essentials in more detail!
Special topics
- Imports vs Depends
- Compiled code in the package see here
- RCPP (integration or R and C++) see here
- Boost see here
- Testing see here
Submitting to CRAN tips / checklist
Especially if you do this for the first time, read
- The official CRAN Policy
- Hadley’s release recommendations
- Google for experience with CRAN submission to see what people struggle with - CRAN is super strict about spelling, capitalization, use of “ and ‘ and so on - if the checks give you a warning, fix it
Checklist for submission
- Update your R system (ideally)
- Run unit tests and CRAN checks in Rstudio, fix all the issues
- Advance version numbers, readme, vignette, date, etc.
- Run again local tests now including
- Unit and Check in RStudion
- Reverse dependencies
- winbuilder on stable and dev
- Ubuntu (via Travis-CI)
- Push new version to GH
- Submit to CRAN