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 anddocumentation
DESCRIPTIONPackage: RODProtType: PackageTitle: JSON Table Schemas from RVersion: 0.1.3Date: 2013-04-22Author: Jeffrey D. Allen <email@example.com>Maintainer: Jeffrey D. Allen <firstname.lastname@example.org>Description: An R Client for Interacting with Data Encoded inone of the Open Data Protocols Standards including JSONTable Schemas.Imports:rjson (>= 0.2.10),RCurl,License: MIT
Tools You’ll Want(Why this talk is only 30 minutes long.)
roxygen2• R Documentation(Rd) formato LaTeX-like, very fickleo Bad error checkinghttps://github.com/klutometis/roxygen
roxygen2• Roxygen2 is an Rpackage• Documentation is inyour R code• Compiles Rd files foryou• Integrated intoRStudio IDEhttps://github.com/klutometis/roxygen
devtools• An R package• Designed to make package authorshipsimpler• Integrated into RStudio IDEhttps://github.com/hadley/devtools/
Steps1. Install devtools and roxygen22. Create an RStudio project with “package” buildmode.1. Set to roxygenize on all three possibilities2. Set to build NAMESPACE, collate, and man fields3. 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
Steps9. Build and Reload10.Test & debug R code, go back to step 911.Check package before submittingo --no-manual if you don’t have pdflatex
How to Get Help• Authoritative Manualo http://cran.us.r-project.org/doc/manuals/R-exts.html• Other Presentationso http://dl.dropboxusercontent.com/u/41902/easy-packages3.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
Outstanding QuestionHow to make use of other packages?
Using Other Packages• Short answer: imports• Long answer:o http://cran.r-project.org/doc/manuals/R-exts.html#Package-namespaceso http://stackoverflow.com/questions/9893791/imports-and-dependso http://stackoverflow.com/questions/8637993/better-explanation-of-when-to-use-imports-depends• Rule of thumb: Don’t use “depends” inDESCRIPTION. There’s a better way now.
Distribution• CRANo http://xmpalantir.wu.ac.at/cransubmit/o Are there any Errors? Warnings? Playing by the rules?• Bioconductoro http://www.bioconductor.org/developers/package-submission/o More rigorous check, actually care about your codequality.o 6 month release cycle• GitHub*o https://github.com/o D.I.Y.* Start here
Tips• Study and emulate the expertso 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