Producing an R Package

Han Oostdijk


Things to remember:

Use Document , Clean and Rebuild, Test Package in the Build tab.

To include vignettes use devtools::install(build_vignettes=TRUE).

When testing in the package project use Load All in the Build tab.

Create a new package (example)

This section documents how I created the package tabraux. I can not get the GitHub connection working unless I start with a GitHub repository. Therefore:

First create interactively a new GitHub repository

Do this by choosing new in the GitHub desktop and filling in the following screen:

This generates repository

Create a new project in RStudio

Indicate in RStudio that you want to create a new project:

Execute the following code in a new session and answer No way on the question Overwrite pre-existing file 'tabraux.Rproj'?. Because in a later step the documentation could not be produced (in first instance) maybe it is better to answer yes. (However I was wondering if the Git-connection was at risk)


Create a DESCRIPTION file

Execute the following code and


and edit the DESCRIPTION file so that it looks like (in my case)

Package: tabraux
Title: Auxiliary functions for package tabr
    person(given = "Han",
           family = "Oostdijk",
           role = c("aut", "cre"),
           email = "",
           comment = c(ORCID = "0000-0001-6710-4566"))
Description: Auxiliary functions for package tabr.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.0.2

Create a README.Rmd file

On GitHub the file was already created but we also create a README.Rmd file:


After executing this code we copy the contents of the .md file and knit the .Rmd document so that the two files are in sync.

Create the testthat structure

Copy the file tabraux.R to the R subfolder and generate a test structure for it. Actual tests will be done later on.


Indicate the packages that will be used


Create the file

After committing all files to Git the file was created:


Build the documentation and the package

I did not see the Document menu choice in the Build tab. However I could choose there Configure Build Tools ... and indicate that I want to use Roxygen. After that I could use the Document and afterwards the Clean and Rebuild options in the Build tab.

devtools::document(roclets = c('rd', 'collate', 'namespace')) # Document (control-shift-D)
# Rcmd.exe INSTALL --preclean --no-multiarch --with-keep.source tabraux # Clean and Rebuild