Skip to content
Tags

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

Advertisements

From → R

Leave a Comment

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

Let's Look at the Figures

David Firth's blog

Nicholas Tierney

Computational Bayesian statistics

One weiRd tip

Computational Bayesian statistics

Series B'log

discussion blog for JRSS Series B papers

Mad (Data) Scientist

Musings, useful code etc. on R and data science

R-bloggers

R news and tutorials contributed by (750) R bloggers

Another Astrostatistics Blog

The random musings of a reformed astronomer ...

Darren Wilkinson's research blog

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

CHANCE

Computational Bayesian statistics

StatsLife - Significance magazine

Computational Bayesian statistics

(badness 10000)

Computational Bayesian statistics

Igor's Blog

Computational Bayesian statistics

Statisfaction

I can't get no

Xi'an's Og

an attempt at bloggin, nothing more...

Sam Clifford

Postdoctoral Fellow, Bayesian Statistics, Aerosol Science

Bayesian Research & Applications Group

Frontier Research in Bayesian Methodology & Computation

%d bloggers like this: