23
R Packages QBRC Tech Talks Jeff Allen June 24, 2013

Creating R Packages

  • Upload
    jalle6

  • View
    1.496

  • Download
    6

Embed Size (px)

DESCRIPTION

An overview of how to create R packages within the RStudio IDE using devtools and roxygen2.

Citation preview

Page 1: Creating R Packages

R PackagesQBRC Tech Talks

Jeff AllenJune 24, 2013

Page 2: Creating R Packages

Overview• Introduction• Tools• Walkthrough• Resources

Page 3: Creating R Packages

Introduction(Why should I care?)

Page 4: Creating R Packages

R Packages• Share R code with another R programmer• Can be hosted in public repositories

(CRAN, Bioconductor, GitHub)• Can contain code in other languages

(Fortran, C++, etc.)• In addition to code, can contain data and

documentation

Page 5: Creating R Packages

Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE

Page 6: Creating R Packages

Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE

Out of Scope

Page 7: Creating R Packages

Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE

Auto-Generated

Page 8: Creating R Packages

Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE

Our responsibilities

Page 9: Creating R Packages

DESCRIPTIONPackage: RODProtType: PackageTitle: JSON Table Schemas from RVersion: 0.1.3Date: 2013-04-22Author: Jeffrey D. Allen <[email protected]>Maintainer: Jeffrey D. Allen <[email protected]>Description: An R Client for Interacting with Data Encoded in one of the 'Open Data Protocols' Standards including JSON Table Schemas.Imports:    rjson (>= 0.2.10),    RCurl,License: MIT

Page 10: Creating R Packages

Tools You’ll Want(Why this talk is only 30 minutes long.)

Page 11: Creating R Packages

roxygen2

• R Documentation (Rd) formato LaTeX-like, very fickleo Bad error checking

https://github.com/klutometis/roxygen

Page 12: Creating R Packages

roxygen2• Roxygen2 is an R

package• Documentation is

in your R code• Compiles Rd files

for you• Integrated into

RStudio IDE

https://github.com/klutometis/roxygen

Page 13: Creating R Packages

devtools• An R package• Designed to make package authorship

simpler• Integrated into RStudio IDE

https://github.com/hadley/devtools/

Page 14: Creating R Packages

Walkthrough(Let’s do it!)

Page 15: Creating R Packages

Steps1. Install devtools and roxygen22. Create an RStudio project with “package” build

mode.1. Set to roxygenize on all three possibilities2. Set to build NAMESPACE, collate, and man fields

3. Create a package directory4. Create an “R” directory5. Put some Roxygenized R code into “./R”6. Load/Install Devtools7. load_all()8. Fill out the description File

Page 16: Creating R Packages

Steps9. Build and Reload10.Test & debug R code, go back to step 911.Check package before submitting

o --no-manual if you don’t have pdflatex

Page 17: Creating R Packages

Resources(How do I …?)

Page 18: Creating R Packages

How to Get Help• Authoritative Manual

o http://cran.us.r-project.org/doc/manuals/R-exts.html

• Other Presentationso http://dl.dropboxusercontent.com/u/41902/easy-packages

3.pdf

• StackOverflowo http://stackoverflow.com/questions/tagged/ro Q & A site with active R community

• Mailing Listso R-devel, Bioconductoro http://www.r-project.org/posting-guide.html#which_listo Do your research; they bite

Page 19: Creating R Packages

Outstanding QuestionHow to make use of other packages?

Page 21: Creating R Packages

Distribution• CRAN

o http://xmpalantir.wu.ac.at/cransubmit/ o Are there any Errors? Warnings? Playing by the rules?

• Bioconductoro http://www.bioconductor.org/developers/package-submis

sion/

o More rigorous check, actually care about your code quality.

o 6 month release cycle

• GitHub*o https://github.com/o D.I.Y.

* Start here

Page 22: Creating R Packages

Tips• Study and emulate the experts

o https://github.com/hadley/stringro https://github.com/yihui/knitr

• Learn Roxygen2o https://github.com/klutometis/roxygen

• Learn devtoolso https://github.com/hadley/devtools/

• Try it at home first…o The campus proxy makes configuration more tedious

Page 23: Creating R Packages

Questions?