4. 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
9. DESCRIPTION
Package: RODProt
Type: Package
Title: JSON Table Schemas from R
Version: 0.1.3
Date: 2013-04-22
Author: Jeffrey D. Allen <jeffrey.allen@utsouthwestern.edu>
Maintainer: Jeffrey D. Allen <jeffrey.allen@utsouthwestern.edu>
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
12. 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
13. devtools
• An R package
• Designed to make package authorship
simpler
• Integrated into RStudio IDE
https://github.com/hadley/devtools/
15. Steps
1. Install devtools and roxygen2
2. Create an RStudio project with “package” build
mode.
1. Set to roxygenize on all three possibilities
2. Set to build NAMESPACE, collate, and man fields
3. Create a package directory
4. Create an “R” directory
5. Put some Roxygenized R code into “./R”
6. Load/Install Devtools
7. load_all()
8. Fill out the description File
16. Steps
9. Build and Reload
10.Test & debug R code, go back to step 9
11.Check package before submitting
o --no-manual if you don’t have pdflatex
18. How to Get Help
• Authoritative Manual
o http://cran.us.r-project.org/doc/manuals/R-exts.html
• Other Presentations
o http://dl.dropboxusercontent.com/u/41902/easy-
packages3.pdf
• StackOverflow
o http://stackoverflow.com/questions/tagged/r
o Q & A site with active R community
• Mailing Lists
o R-devel, Bioconductor
o http://www.r-project.org/posting-guide.html#which_list
o Do your research; they bite
20. Using Other Packages
• Short answer: imports
• Long answer:
o http://cran.r-project.org/doc/manuals/R-exts.html#Package-
namespaces
o http://stackoverflow.com/questions/9893791/imports-and-depends
o http://stackoverflow.com/questions/8637993/better-explanation-of-when-
to-use-imports-depends
• Rule of thumb: Don’t use “depends” in
DESCRIPTION. There’s a better way now.
21. Distribution
• CRAN
o http://xmpalantir.wu.ac.at/cransubmit/
o Are there any Errors? Warnings? Playing by the rules?
• Bioconductor
o http://www.bioconductor.org/developers/package-
submission/
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
22. Tips
• Study and emulate the experts
o https://github.com/hadley/stringr
o https://github.com/yihui/knitr
• Learn Roxygen2
o https://github.com/klutometis/roxygen
• Learn devtools
o https://github.com/hadley/devtools/
• Try it at home first…
o The campus proxy makes configuration more tedious