Skip to content

Write an R package in 10 minutes

December 2, 2015

I have mixed feelings about some of the new features in RStudio v0.99.489, but one thing I really like is the menu command “Insert Roxygen Skeleton.” It has always bugged me that the R package created by a call to utils::package.skeleton(..) doesn’t pass R CMD check without a bunch of manual changes. Editing .Rd files by hand isn’t my idea of fun, so I’m much happier with the new workflow:

  1. Start from an empty RStudio workspace (this means that the Environment window should be completely empty)
  2. Source all of the miscellaneous .R scripts, where you keep the handy functions that you find yourself using all the time. You should now be able to see these functions listed in the Environment window.
  3. Make up a name for your new R package. Following Hadley’s advice, Google it to make sure it isn’t already taken.
  4. Call package.skeleton(“myPackage”) to create a new R package in the current working directory.
  5. Open up each of the files in the R subdirectory (there should be one for each function) and use “Insert Roxygen Skeleton”
  6. library(roxygen2); roxygenise(“myPackage”)
  7. Open up the myPackage-package.Rd file in the man subdirectory (the main help file for your package). Comment out everything inside \examples{ .. }
  8. R CMD build, R CMD check, R CMD INSTALL should now all work.

I presented this as a live demo for the Young Researchers’ Meeting at the Department of Statistics, University of Warwick. It probably took me more than 5 minutes as I had to explain each of the steps, but it demonstrates that creating an R package is easier than it has ever been. Following my own experience, I would recommend any PhD student in statistics to strongly consider it as a great way to promote your research.

Here is an example of an R package that I created using the above method, and here is the online help as a PDF file: bayesMoG-manual

From → R

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Ella Kaye on Ella Kaye

Computational Bayesian statistics

Bayes' Food Cake

A bit of statistics, a bit of cakes. - Blogs to Learn R from the Community

Computational Bayesian statistics

Richard Everitt's blog

Computational Bayesian statistics

Let's Look at the Figures

David Firth's blog

Nicholas Tierney

Computational Bayesian statistics

Sweet Tea, Science

Two southern scientistas will be bringing you all that is awesome in STEM as we complete our PhDs. Ecology, statistics, sass.

Mad (Data) Scientist

Musings, useful code etc. on R and data science

Darren Wilkinson's blog

Statistics, computing, functional programming, data science, Bayes, stochastic modelling, systems biology and bioinformatics

(badness 10000)

Computational Bayesian statistics

Igor Kromin

Computational Bayesian statistics


I can't get no

Xi'an's Og

an attempt at bloggin, nothing more...

Sam Clifford

Postdoctoral Fellow, Bayesian Statistics, Aerosol Science

%d bloggers like this: