Permalink
Browse files

Add .inform argument to **ply.

Closes #57
  • Loading branch information...
1 parent a3c8618 commit b665d958a0aa7dd395de3961b46cdfc9dc5d99ad @hadley committed Oct 11, 2012
Showing with 184 additions and 103 deletions.
  1. +2 −0 NEWS
  2. +2 −2 R/a_ply.r
  3. +4 −4 R/aaply.r
  4. +4 −2 R/adply.r
  5. +4 −2 R/alply.r
  6. +4 −4 R/d_ply.r
  7. +4 −3 R/daply.r
  8. +4 −2 R/ddply.r
  9. +4 −2 R/dlply.r
  10. +2 −2 R/l_ply.r
  11. +4 −3 R/laply.r
  12. +3 −2 R/ldply.r
  13. +0 −3 R/llply.r
  14. +4 −3 R/m_ply.r
  15. +4 −3 R/maply.r
  16. +3 −3 R/mdply.r
  17. +3 −3 R/mlply.r
  18. +5 −2 man-roxygen/ply.r
  19. +8 −4 man/a_ply.Rd
  20. +8 −4 man/aaply.Rd
  21. +8 −3 man/adply.Rd
  22. +8 −3 man/alply.Rd
  23. +8 −4 man/d_ply.Rd
  24. +8 −4 man/daply.Rd
  25. +8 −4 man/ddply.Rd
  26. +8 −4 man/dlply.Rd
  27. +8 −3 man/l_ply.Rd
  28. +8 −3 man/laply.Rd
  29. +7 −3 man/ldply.Rd
  30. +5 −5 man/llply.Rd
  31. +8 −4 man/m_ply.Rd
  32. +8 −4 man/maply.Rd
  33. +8 −3 man/mdply.Rd
  34. +8 −3 man/mlply.Rd
View
@@ -1,6 +1,8 @@
Version 1.7.1.99
------------------------------------------------------------------------------
+* `**ply` gain a `.inform` argument (previously only available in `llply`) - this gives more useful debugging information at the cost of some speed. (Thanks to Brian Diggs, #57)
+
* `**ply` gains a `.paropts` argumetns, a list of options that is passed onto `foreach` for controlling parallel computation.
* New function `here` makes it possible to use `**ply` + a function that uses non-standard evaluation (e.g. `summarise`, `mutate`, `subset`, `arrange`) inside a function. (Thanks to Peter Meilstrup, #3)
View
@@ -7,8 +7,8 @@
#' @template -_
#' @export
a_ply <- function(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .print = FALSE, .parallel = FALSE,
- .paropts = NULL) {
+ .progress = "none", .inform = FALSE,
+ .print = FALSE, .parallel = FALSE, .paropts = NULL) {
pieces <- splitter_a(.data, .margins, .expand)
l_ply(.data = pieces, .fun = .fun, ...,
View
@@ -31,11 +31,11 @@
#'
#' aaply(ozone, 1:2, diff)
aaply <- function(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .drop = TRUE, .parallel = FALSE,
- .paropts = NULL) {
+ .progress = "none", .inform = FALSE, .drop = TRUE,
+ .parallel = FALSE, .paropts = NULL) {
pieces <- splitter_a(.data, .margins, .expand)
laply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .drop = .drop, .parallel = .parallel,
- .paropts = .paropts)
+ .progress = .progress, .inform = .inform, .drop = .drop,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -8,9 +8,11 @@
#' @template -d
#' @export
adply <- function(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .parallel = FALSE, .paropts = NULL) {
+ .progress = "none", .inform = FALSE, .parallel = FALSE,
+ .paropts = NULL) {
pieces <- splitter_a(.data, .margins, .expand)
ldply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -14,9 +14,11 @@
#' alply(ozone, 3, quantile)
#' alply(ozone, 3, function(x) table(round(x)))
alply <- function(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .parallel = FALSE, .paropts = NULL) {
+ .progress = "none", .inform = FALSE, .parallel = FALSE,
+ .paropts = NULL) {
pieces <- splitter_a(.data, .margins, .expand)
llply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -7,12 +7,12 @@
#' @template -_
#' @export
d_ply <- function(.data, .variables, .fun = NULL, ..., .progress = "none",
- .drop = TRUE, .print = FALSE, .parallel = FALSE,
- .paropts = NULL) {
+ .inform = FALSE, .drop = TRUE, .print = FALSE,
+ .parallel = FALSE, .paropts = NULL) {
.variables <- as.quoted(.variables)
pieces <- splitter_d(.data, .variables, .drop = .drop)
l_ply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .print = .print, .parallel = .parallel,
- .paropts = .paropts)
+ .progress = .progress, .inform = .inform, .print = .print,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -32,11 +32,12 @@
#' daply(baseball[, 6:9], .(baseball$year), colwise(mean))
#' daply(baseball, .(year), function(df) colwise(mean)(df[, 6:9]))
daply <- function(.data, .variables, .fun = NULL, ..., .progress = "none",
- .drop_i = TRUE, .drop_o = TRUE, .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .drop_i = TRUE, .drop_o = TRUE, .parallel = FALSE,
+ .paropts = NULL) {
.variables <- as.quoted(.variables)
pieces <- splitter_d(.data, .variables, drop = .drop_i)
laply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .drop = .drop_o, .parallel = .parallel,
- .paropts = .paropts)
+ .progress = .progress, .inform = .inform, .drop = .drop_o,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -47,11 +47,13 @@
#' career_year = year - min(year) + 1
#' )
ddply <- function(.data, .variables, .fun = NULL, ..., .progress = "none",
- .drop = TRUE, .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .drop = TRUE, .parallel = FALSE,
+ .paropts = NULL) {
if (empty(.data)) return(.data)
.variables <- as.quoted(.variables)
pieces <- splitter_d(.data, .variables, drop = .drop)
ldply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -20,10 +20,12 @@
#' qual <- laply(models, function(mod) summary(mod)$r.squared)
#' hist(qual)
dlply <- function(.data, .variables, .fun = NULL, ..., .progress = "none",
- .drop = TRUE, .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .drop = TRUE, .parallel = FALSE,
+ .paropts = NULL) {
.variables <- as.quoted(.variables)
pieces <- splitter_d(.data, .variables, drop = .drop)
llply(.data = pieces, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -6,8 +6,8 @@
#' @template l-
#' @template -_
#' @export
-l_ply <- function(.data, .fun = NULL, ..., .progress = "none", .print = FALSE,
- .parallel = FALSE, .paropts = NULL) {
+l_ply <- function(.data, .fun = NULL, ..., .progress = "none", .inform = FALSE,
+ .print = FALSE, .parallel = FALSE, .paropts = NULL) {
if (is.character(.fun) || is.list(.fun)) .fun <- each(.fun)
if (!is.function(.fun)) stop(".fun is not a function.")
View
@@ -21,14 +21,15 @@
#' laply(seq_len(10), identity)
#' laply(seq_len(10), rep, times = 4)
#' laply(seq_len(10), matrix, nrow = 2, ncol = 2)
-laply <- function(.data, .fun = NULL, ..., .progress = "none", .drop = TRUE,
- .parallel = FALSE, .paropts = NULL) {
+laply <- function(.data, .fun = NULL, ..., .progress = "none", .inform = FALSE,
+ .drop = TRUE, .parallel = FALSE, .paropts = NULL) {
if (is.character(.fun)) .fun <- do.call("each", as.list(.fun))
if (!is.function(.fun)) stop(".fun is not a function.")
if (!inherits(.data, "split")) .data <- as.list(.data)
res <- llply(.data = .data, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
list_to_array(res, attr(.data, "split_labels"), .drop)
}
View
@@ -7,11 +7,12 @@
#' @template l-
#' @template -d
#' @export
-ldply <- function(.data, .fun = NULL, ..., .progress = "none",
+ldply <- function(.data, .fun = NULL, ..., .progress = "none", .inform = FALSE,
.parallel = FALSE, .paropts = NULL) {
if (!inherits(.data, "split")) .data <- as.list(.data)
res <- llply(.data = .data, .fun = .fun, ...,
- .progress = .progress, .parallel = .parallel, .paropts = .paropts)
+ .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
list_to_dataframe(res, attr(.data, "split_labels"))
}
View
@@ -8,9 +8,6 @@
#' @template ply
#' @template l-
#' @template -l
-#' @param .inform produce informative error messages? This is turned off by
-#' by default because it substantially slows processing speed, but is very
-#' useful for debugging
#' @export
#' @examples
#' llply(llply(mtcars, round), table)
View
@@ -8,11 +8,12 @@
#' @template -_
#' @export
m_ply <- function(.data, .fun = NULL, ..., .expand = TRUE, .progress = "none",
- .print = FALSE, .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .print = FALSE, .parallel = FALSE,
+ .paropts = NULL) {
if (is.matrix(.data) & !is.list(.data)) .data <- .matrix_to_df(.data)
f <- splat(.fun)
a_ply(.data = .data, .margins = 1, .fun = f, ..., .expand = .expand,
- .progress = .progress, .print = .print, .parallel = .parallel,
- .paropts = .paropts)
+ .progress = .progress, .inform = .inform, .print = .print,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -12,11 +12,12 @@
#' maply(expand.grid(mean = 1:5, sd = 1:5), rnorm, n = 5)
#' maply(cbind(1:5, 1:5), rnorm, n = 5)
maply <- function(.data, .fun = NULL, ..., .expand = TRUE, .progress = "none",
- .drop = TRUE, .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .drop = TRUE, .parallel = FALSE,
+ .paropts = NULL) {
if (is.matrix(.data) & !is.list(.data)) .data <- .matrix_to_df(.data)
f <- splat(.fun)
aaply(.data = .data, .margins = 1, .fun = f, ...,
- .expand = .expand, .progress = .progress, .parallel = .parallel,
- .paropts = .paropts, .drop = .drop)
+ .expand = .expand, .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts, .drop = .drop)
}
View
@@ -13,11 +13,11 @@
#' mdply(cbind(mean = 1:5, sd = 1:5), rnorm, n = 5)
#' mdply(cbind(mean = 1:5, sd = 1:5), as.data.frame(rnorm), n = 5)
mdply <- function(.data, .fun = NULL, ..., .expand = TRUE, .progress = "none",
- .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .parallel = FALSE, .paropts = NULL) {
if (is.matrix(.data) & !is.list(.data)) .data <- .matrix_to_df(.data)
f <- splat(.fun)
adply(.data = .data, .margins = 1, .fun = f, ...,
- .expand = .expand, .progress = .progress, .parallel = .parallel,
- .paropts = .paropts)
+ .expand = .expand, .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -15,11 +15,11 @@
#' mlply(cbind(1:4, length = 4:1), seq)
#' mlply(cbind(1:4, by = 4:1), seq, to = 20)
mlply <- function(.data, .fun = NULL, ..., .expand = TRUE, .progress = "none",
- .parallel = FALSE, .paropts = NULL) {
+ .inform = FALSE, .parallel = FALSE, .paropts = NULL) {
if (is.matrix(.data) & !is.list(.data)) .data <- .matrix_to_df(.data)
f <- splat(.fun)
alply(.data = .data, .margins = 1, .fun = f, ...,
- .expand = .expand, .progress = .progress, .parallel = .parallel,
- .paropts = .paropts)
+ .expand = .expand, .progress = .progress, .inform = .inform,
+ .parallel = .parallel, .paropts = .paropts)
}
View
@@ -2,14 +2,17 @@
#' @param ... other arguments passed on to \code{.fun}
#' @param .progress name of the progress bar to use, see
#' \code{\link{create_progress_bar}}
+#' @param .parallel if \code{TRUE}, apply function in parallel, using parallel
+#' backend provided by foreach
#' @param .paropts a list of additional options passed into
#' the \code{\link[foreach]{foreach}} function when parallel computation
#' is enabled. This is important if (for example) your code relies on
#' external data or packages: use the \code{.export} and \code{.packages}
#' arguments to supply them so that all cluster nodes have the correct
#' environment set up for computing.
-#' @param .parallel if \code{TRUE}, apply function in parallel, using parallel
-#' backend provided by foreach
+#' @param .inform produce informative error messages? This is turned off by
+#' by default because it substantially slows processing speed, but is very
+#' useful for debugging
#' @keywords manip
#' @references Hadley Wickham (2011). The Split-Apply-Combine Strategy
#' for Data Analysis. Journal of Statistical Software, 40(1), 1-29.
View
@@ -3,8 +3,8 @@
\title{Split array, apply function, and discard results.}
\usage{
a_ply(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .print = FALSE, .parallel = FALSE,
- .paropts = NULL)
+ .progress = "none", .inform = FALSE, .print = FALSE,
+ .parallel = FALSE, .paropts = NULL)
}
\arguments{
\item{.fun}{function to apply to each piece}
@@ -14,6 +14,9 @@
\item{.progress}{name of the progress bar to use, see
\code{\link{create_progress_bar}}}
+ \item{.parallel}{if \code{TRUE}, apply function in
+ parallel, using parallel backend provided by foreach}
+
\item{.paropts}{a list of additional options passed into
the \code{\link[foreach]{foreach}} function when parallel
computation is enabled. This is important if (for
@@ -22,8 +25,9 @@
supply them so that all cluster nodes have the correct
environment set up for computing.}
- \item{.parallel}{if \code{TRUE}, apply function in
- parallel, using parallel backend provided by foreach}
+ \item{.inform}{produce informative error messages? This
+ is turned off by by default because it substantially
+ slows processing speed, but is very useful for debugging}
\item{.data}{matrix, array or data frame to be processed}
View
@@ -3,8 +3,8 @@
\title{Split array, apply function, and return results in an array.}
\usage{
aaply(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .drop = TRUE, .parallel = FALSE,
- .paropts = NULL)
+ .progress = "none", .inform = FALSE, .drop = TRUE,
+ .parallel = FALSE, .paropts = NULL)
}
\arguments{
\item{.fun}{function to apply to each piece}
@@ -14,6 +14,9 @@
\item{.progress}{name of the progress bar to use, see
\code{\link{create_progress_bar}}}
+ \item{.parallel}{if \code{TRUE}, apply function in
+ parallel, using parallel backend provided by foreach}
+
\item{.paropts}{a list of additional options passed into
the \code{\link[foreach]{foreach}} function when parallel
computation is enabled. This is important if (for
@@ -22,8 +25,9 @@
supply them so that all cluster nodes have the correct
environment set up for computing.}
- \item{.parallel}{if \code{TRUE}, apply function in
- parallel, using parallel backend provided by foreach}
+ \item{.inform}{produce informative error messages? This
+ is turned off by by default because it substantially
+ slows processing speed, but is very useful for debugging}
\item{.data}{matrix, array or data frame to be processed}
View
@@ -3,7 +3,8 @@
\title{Split array, apply function, and return results in a data frame.}
\usage{
adply(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .parallel = FALSE, .paropts = NULL)
+ .progress = "none", .inform = FALSE, .parallel = FALSE,
+ .paropts = NULL)
}
\arguments{
\item{.fun}{function to apply to each piece}
@@ -13,6 +14,9 @@
\item{.progress}{name of the progress bar to use, see
\code{\link{create_progress_bar}}}
+ \item{.parallel}{if \code{TRUE}, apply function in
+ parallel, using parallel backend provided by foreach}
+
\item{.paropts}{a list of additional options passed into
the \code{\link[foreach]{foreach}} function when parallel
computation is enabled. This is important if (for
@@ -21,8 +25,9 @@
supply them so that all cluster nodes have the correct
environment set up for computing.}
- \item{.parallel}{if \code{TRUE}, apply function in
- parallel, using parallel backend provided by foreach}
+ \item{.inform}{produce informative error messages? This
+ is turned off by by default because it substantially
+ slows processing speed, but is very useful for debugging}
\item{.data}{matrix, array or data frame to be processed}
View
@@ -3,7 +3,8 @@
\title{Split array, apply function, and return results in a list.}
\usage{
alply(.data, .margins, .fun = NULL, ..., .expand = TRUE,
- .progress = "none", .parallel = FALSE, .paropts = NULL)
+ .progress = "none", .inform = FALSE, .parallel = FALSE,
+ .paropts = NULL)
}
\arguments{
\item{.fun}{function to apply to each piece}
@@ -13,6 +14,9 @@
\item{.progress}{name of the progress bar to use, see
\code{\link{create_progress_bar}}}
+ \item{.parallel}{if \code{TRUE}, apply function in
+ parallel, using parallel backend provided by foreach}
+
\item{.paropts}{a list of additional options passed into
the \code{\link[foreach]{foreach}} function when parallel
computation is enabled. This is important if (for
@@ -21,8 +25,9 @@
supply them so that all cluster nodes have the correct
environment set up for computing.}
- \item{.parallel}{if \code{TRUE}, apply function in
- parallel, using parallel backend provided by foreach}
+ \item{.inform}{produce informative error messages? This
+ is turned off by by default because it substantially
+ slows processing speed, but is very useful for debugging}
\item{.data}{matrix, array or data frame to be processed}
Oops, something went wrong.

0 comments on commit b665d95

Please sign in to comment.