Creating R Packages
-
Upload
jalle6 -
Category
Technology
-
view
1.494 -
download
6
description
Transcript of Creating R Packages
R PackagesQBRC Tech Talks
Jeff AllenJune 24, 2013
Overview• Introduction• Tools• Walkthrough• Resources
Introduction(Why should I care?)
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
Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE
Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE
Out of Scope
Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE
Auto-Generated
Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE
Our responsibilities
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
Tools You’ll Want(Why this talk is only 30 minutes long.)
roxygen2
• R Documentation (Rd) formato LaTeX-like, very fickleo Bad error checking
https://github.com/klutometis/roxygen
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
devtools• An R package• Designed to make package authorship
simpler• Integrated into RStudio IDE
https://github.com/hadley/devtools/
Walkthrough(Let’s do it!)
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
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
Resources(How do I …?)
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
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-namespaces
o http://stackoverflow.com/questions/9893791/imports-and-dependso http://stackoverflow.com/questions/8637993/better-explanation-of-whe
n-to-use-imports-depends
• Rule of thumb: Don’t use “depends” in DESCRIPTION. There’s a better way now.
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
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
Questions?