Creating R Packages


Published on

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

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Build & ReloadCheck--no-manual in CHECK
  • Creating R Packages

    1. 1. R PackagesQBRC Tech TalksJeff AllenJune 24, 2013
    2. 2. Overview• Introduction• Tools• Walkthrough• Resources
    3. 3. Introduction(Why should I care?)
    4. 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 anddocumentation
    5. 5. Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACE
    6. 6. Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACEOut of Scope
    7. 7. Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACEAuto-Generated
    8. 8. Ingredients• /R• /man• /inst• /src• DESCRIPTION• NAMESPACEOur responsibilities
    9. 9. DESCRIPTIONPackage: RODProtType: PackageTitle: JSON Table Schemas from RVersion: 0.1.3Date: 2013-04-22Author: Jeffrey D. Allen <>Maintainer: Jeffrey D. Allen <>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
    10. 10. Tools You’ll Want(Why this talk is only 30 minutes long.)
    11. 11. roxygen2• R Documentation(Rd) formato LaTeX-like, very fickleo Bad error checking
    12. 12. roxygen2• Roxygen2 is an Rpackage• Documentation is inyour R code• Compiles Rd files foryou• Integrated intoRStudio IDE
    13. 13. devtools• An R package• Designed to make package authorshipsimpler• Integrated into RStudio IDE
    14. 14. Walkthrough(Let’s do it!)
    15. 15. 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
    16. 16. 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
    17. 17. Resources(How do I …?)
    18. 18. How to Get Help• Authoritative Manualo• Other Presentationso• StackOverflowo Q & A site with active R community• Mailing Listso R-devel, Bioconductoro Do your research; they bite
    19. 19. Outstanding QuestionHow to make use of other packages?
    20. 20. Using Other Packages• Short answer: imports• Long answer:o• Rule of thumb: Don’t use “depends” inDESCRIPTION. There’s a better way now.
    21. 21. Distribution• CRANo Are there any Errors? Warnings? Playing by the rules?• Bioconductoro More rigorous check, actually care about your codequality.o 6 month release cycle• GitHub*o D.I.Y.* Start here
    22. 22. Tips• Study and emulate the expertso• Learn Roxygen2o• Learn devtoolso• Try it at home first…o The campus proxy makes configuration more tedious
    23. 23. Questions?