Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
7,016
On Slideshare
7,008
From Embeds
8
Number of Embeds
4

Actions

Shares
Downloads
96
Comments
0
Likes
10

Embeds 8

http://www.edmodo.com 4
https://twitter.com 2
http://us-w1.rockmelt.com 1
http://tweetedtimes.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Making an R package Hadley Wickham Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University November 2010 Tuesday, 9 November 2010
  • 2. What I’ve learned from developing 20+ R packages https://github.com/ hadley/devtools/wiki Tuesday, 9 November 2010
  • 3. op W te in io ar d na ni a ng dv 1. Getting started : ic 2. Development cycle e 3. Documentation 4. What to learn next Tuesday, 9 November 2010
  • 4. Use a mac! (or linux) Otherwise, start by downloading and installing http://www.murdoch-sutherland.com/Rtools/ Tuesday, 9 November 2010
  • 5. Getting started Tuesday, 9 November 2010
  • 6. 1. Decide on a name (stringr) !"" R 2. Create stringr/ and #   !"" file1.r stringr/R/ #   !"" file2.r directories 3. Copy in your existing code Tuesday, 9 November 2010
  • 7. !"" DESCRIPTION 4. Add a description file !"" R Tuesday, 9 November 2010
  • 8. Package: stringr Type: Package Title: Make it easier to work with strings. Version: 0.5 Author: Hadley Wickham <h.wickham@gmail.com> Maintainer: Hadley Wickham <h.wickham@gmail.com> Description: stringr is a set of simple wrappers that make R's string functions more consistent, simpler and easier to use. It does this by ensuring that: function and argument names (and positions) are consistent, all functions deal with NA's and zero length character appropriately, and the output data structures from each function matches the input data structures of other functions. Imports: plyr Depends: R (>= 2.11.0) Suggests: testthat (>= 0.3) License: GPL-2 https://github.com/hadley/devtools/wiki/Package-basics Tuesday, 9 November 2010
  • 9. !"" DESCRIPTION 4. Document your files !"" man 5. Run roxygenize() !"" R Tuesday, 9 November 2010
  • 10. #' The length of a string (in characters). #' #' @param string input character vector #' @return numeric vector giving number of characters in #' each element of the character vector. Missing strings have #' missing length. #' @keywords character #' @seealso code{link{nchar}} which this function wraps #' @export #' @examples #' str_length(letters) #' str_length(c("i", "like", "programming", NA)) str_length <- function(string) { string <- check_string(string) nc <- nchar(string, allowNA = TRUE) is.na(nc) <- is.na(string) nc } https://github.com/hadley/devtools/wiki/docs-function Tuesday, 9 November 2010
  • 11. 6. Run R CMD check 7. Use R CMD build to !"" DESCRIPTION create a package file !"" man 8. Upload file to CRAN: !"" R ftp -u ftp://cran.R- project.org/incoming/ stringr_0.5.tar.gz https://github.com/hadley/devtools/wiki/Release Tuesday, 9 November 2010
  • 12. You’re done! Tuesday, 9 November 2010
  • 13. Development cycle Tuesday, 9 November 2010
  • 14. Exploratory programming Identify the Modify and task save code NO Reload in R Write an Does it work? YES automated test Tuesday, 9 November 2010
  • 15. Confirmatory programming Write an Modify and automated test save code NO Reload in R Does it work? YES You’re done Tuesday, 9 November 2010
  • 16. # These patterns are facilitated by the devtools # package: https://github.com/hadley/devtools # Once installed and set up you can easily: # * Reload code and data load_all("stringr") # * Run automated tests test("stringr") # * Update documentation document("stringr") Tuesday, 9 November 2010
  • 17. Documentation Tuesday, 9 November 2010
  • 18. Documentation Function-level: gives precise details about individual functions Package-level: gives details about how to use the functions to solve real (complex) problems. Both are essential! Tuesday, 9 November 2010
  • 19. Function-level Keep code and documentation close together with roxygen. Writing documentation gets easier with time! Tuesday, 9 November 2010
  • 20. Package-level Package help topic NEWS Vignettes + CITATION Demos README https://github.com/hadley/devtools/wiki/docs-package Tuesday, 9 November 2010
  • 21. Next... Tuesday, 9 November 2010
  • 22. Learning more Testing Namespaces Code style Git + github Tuesday, 9 November 2010
  • 23. Learn from others Read the source of other packages! https://github.com/hadley/plyr https://github.com/hadley/stringr https://github.com/hadley/lubridate https://github.com/hadley/evaluate https://github.com/hadley/reshape Tuesday, 9 November 2010
  • 24. Tuesday, 9 November 2010
  • 25. This work is licensed under the Creative Commons Attribution-Noncommercial 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/ 3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Tuesday, 9 November 2010