# hadley/plyr

Fixes for R CMD check

• Loading branch information...
hadley committed Oct 12, 2012
1 parent 15d9f60 commit 845328718d14aad488ad842dffe1b54566b4fabd
Showing with 38 additions and 57 deletions.
1. +11 −18 R/ddply.r
2. +4 −0 R/progress.r
3. +4 −4 R/take.r
4. +2 −0 man/create_progress_bar.Rd
5. +11 −18 man/ddply.Rd
6. +2 −0 man/progress_tk.Rd
7. +4 −4 man/take.Rd
8. +0 −13 tests/dependencies.R
 @@ -11,39 +11,32 @@ #' @examples #' # Summarize a dataset by two variables #' require(plyr) -#' group <- c(rep('A', 8), rep('B', 15), rep('C', 6)) -#' sex <- sample(c("M", "F"), size = 29, replace = TRUE) -#' age <- runif(n = 29, min = 18, max = 54) -#' dfx <- data.frame (group, time, age) +#' dfx <- data.frame( +#' group = c(rep('A', 8), rep('B', 15), rep('C', 6)), +#' sex = sample(c("M", "F"), size = 29, replace = TRUE), +#' age = runif(n = 29, min = 18, max = 54) +#' ) #' #' # Note the use of the '.' function to allow #' # group and sex to be used without quoting #' ddply(dfx, .(group, sex), summarize, -#' mean <- round(mean(age), 2), -#' sd <- round(sd(age), 2)) -#' -#' # group sex mean sd -#' # 1 A F 35.89 8.53 -#' # 2 A M 38.01 15.09 -#' # 3 B F 39.08 10.79 -#' # 4 B M 37.38 9.55 -#' # 5 C F 30.01 NA -#' # 6 C M 34.78 11.50 +#' mean = round(mean(age), 2), +#' sd = round(sd(age), 2)) #' #' # An example using a formula for .variables -#' ddply(baseball[1:100,], .variables = ~year, .fun=nrow) +#' ddply(baseball[1:100,], ~ year, nrow) #' # Applying two functions; nrow and ncol -#' ddply(baseball, .(lg), c("nrow", "mean")) +#' ddply(baseball, .(lg), c("nrow", "ncol")) #' #' # Calculate mean runs batted in for each year #' rbi <- ddply(baseball, .(year), summarise, #' mean_rbi = mean(rbi, na.rm = TRUE)) #' # Plot a line chart of the result -#' plot(mean_rbi ~year, type = "l", data = rbi)) +#' plot(mean_rbi ~ year, type = "l", data = rbi) #' #' # make new variable career_year based on the #' # start year for each player (id) -#' base2 <- ddply(baseball, .(id), transform, +#' base2 <- ddply(baseball, .(id), mutate, #' career_year = year - min(year) + 1 #' ) ddply <- function(.data, .variables, .fun = NULL, ..., .progress = "none",
 @@ -28,8 +28,10 @@ #' @examples #' # No progress bar #' l_ply(1:100, identity, .progress = "none") +#' \dontrun{ #' # Use the Tcl/Tk interface #' l_ply(1:100, identity, .progress = "tk") +#' } #' # Text-based progress (|======|) #' l_ply(1:100, identity, .progress = "text") #' # Choose a progress character, run a length of time you can see @@ -111,9 +113,11 @@ progress_text <- function(style = 3, ...) { #' @family progress bars #' @export #' @examples +#' \dontrun{ #' l_ply(1:100, identity, .progress = "tk") #' l_ply(1:100, identity, .progress = progress_tk(width=400)) #' l_ply(1:100, identity, .progress = progress_tk(label="")) +#' } progress_tk <- function(title = "plyr progress", label = "Working...", ...) { stopifnot(require("tcltk", quiet=TRUE)) n <- 0
 @@ -2,7 +2,7 @@ #' #' @param x matrix or array to subset #' @param along dimension to subset along -#' @param indices +#' @param indices the indices to select #' @param drop should the dimensions of the array be simplified? Defaults #' to \code{FALSE} which is the opposite of the useful R default. #' @export @@ -11,9 +11,9 @@ #' take(x, 3, 1) #' take(x, 2, 1) #' take(x, 1, 1) -#' take(x, 3, 1, drop = TRU) -#' take(x, 2, 1, drop = TRU) -#' take(x, 1, 1, drop = TRU) +#' take(x, 3, 1, drop = TRUE) +#' take(x, 2, 1, drop = TRUE) +#' take(x, 1, 1, drop = TRUE) take <- function(x, along, indices, drop = FALSE) { nd <- length(dim(x))
 @@ -39,8 +39,10 @@ \examples{ # No progress bar l_ply(1:100, identity, .progress = "none") +\dontrun{ # Use the Tcl/Tk interface l_ply(1:100, identity, .progress = "tk") +} # Text-based progress (|======|) l_ply(1:100, identity, .progress = "text") # Choose a progress character, run a length of time you can see
 @@ -65,39 +65,32 @@ \examples{ # Summarize a dataset by two variables require(plyr) -group <- c(rep('A', 8), rep('B', 15), rep('C', 6)) -sex <- sample(c("M", "F"), size = 29, replace = TRUE) -age <- runif(n = 29, min = 18, max = 54) -dfx <- data.frame (group, time, age) +dfx <- data.frame( + group = c(rep('A', 8), rep('B', 15), rep('C', 6)), + sex = sample(c("M", "F"), size = 29, replace = TRUE), + age = runif(n = 29, min = 18, max = 54) +) # Note the use of the '.' function to allow # group and sex to be used without quoting ddply(dfx, .(group, sex), summarize, - mean <- round(mean(age), 2), - sd <- round(sd(age), 2)) - -# group sex mean sd -# 1 A F 35.89 8.53 -# 2 A M 38.01 15.09 -# 3 B F 39.08 10.79 -# 4 B M 37.38 9.55 -# 5 C F 30.01 NA -# 6 C M 34.78 11.50 + mean = round(mean(age), 2), + sd = round(sd(age), 2)) # An example using a formula for .variables -ddply(baseball[1:100,], .variables = ~year, .fun=nrow) +ddply(baseball[1:100,], ~ year, nrow) # Applying two functions; nrow and ncol -ddply(baseball, .(lg), c("nrow", "mean")) +ddply(baseball, .(lg), c("nrow", "ncol")) # Calculate mean runs batted in for each year rbi <- ddply(baseball, .(year), summarise, mean_rbi = mean(rbi, na.rm = TRUE)) # Plot a line chart of the result -plot(mean_rbi ~year, type = "l", data = rbi)) +plot(mean_rbi ~ year, type = "l", data = rbi) # make new variable career_year based on the # start year for each player (id) -base2 <- ddply(baseball, .(id), transform, +base2 <- ddply(baseball, .(id), mutate, career_year = year - min(year) + 1 ) }
 @@ -20,10 +20,12 @@ This graphical progress will appear in a separate window. } \examples{ +\dontrun{ l_ply(1:100, identity, .progress = "tk") l_ply(1:100, identity, .progress = progress_tk(width=400)) l_ply(1:100, identity, .progress = progress_tk(label="")) } +} \seealso{ \code{\link[tcltk]{tkProgressBar}} for the function that powers this progress bar
 @@ -9,7 +9,7 @@ \item{along}{dimension to subset along} - \item{indices}{} + \item{indices}{the indices to select} \item{drop}{should the dimensions of the array be simplified? Defaults to \code{FALSE} which is the @@ -23,8 +23,8 @@ x <- array(seq_len(3 * 4 * 5), c(3, 4, 5)) take(x, 3, 1) take(x, 2, 1) take(x, 1, 1) -take(x, 3, 1, drop = TRU) -take(x, 2, 1, drop = TRU) -take(x, 1, 1, drop = TRU) +take(x, 3, 1, drop = TRUE) +take(x, 2, 1, drop = TRUE) +take(x, 1, 1, drop = TRUE) }
 @@ -1,13 +0,0 @@ -if (Sys.info()["user"] == "hadley") { - library(devtools) - # check("reshape2", document = FALSE) - check_cran("lubridate") - check_cran("ggplot2") - check_cran("reshape") - check_cran("stringr") - check_cran("nullabor") - check_cran("stringr") - check_cran("productplots") - check_cran("reshape2") - -}

#### 0 comments on commit `8453287`

Please sign in to comment.