Skip to content

Commit

Permalink
Each now accepts vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Apr 12, 2009
1 parent b8be46d commit b763abd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Improvements:

* all ply functions deal more elegantly when given function names: can supply a vector of function names, and name is used as label in output
* failwith and each now work with function names as well as functions (i.e. "nrow" instead of nrow)
* each now accepts a list of functions or a vector of function names
* l*ply will use list names where present
* if .inform is TRUE, error messages will give you information about where errors within your data - hopefully this will make problems easier to track down

Expand Down
10 changes: 10 additions & 0 deletions R/helper-each.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
# @arguments functions to combine
# @keyword manip
#X each(min, max)(1:10)
#X each("min", "max")(1:10)
#X each(c("min", "max"))(1:10)
#X each(c(min, max))(1:10)
#X each(length, mean, var)(rnorm(100))
each <- function(...) {
fnames <- laply(match.call()[-1], deparse)
fs <- list(...)
if (length(fs[[1]]) > 1) {
fs <- fs[[1]]

# Jump through hoops to work out names
snames <- as.list(match.call()[2])[[1]]
fnames <- unlist(lapply(as.list(snames)[-1], deparse))
}

# Find function names and replace with function objects
char <- laply(fs, is.character)
Expand Down

0 comments on commit b763abd

Please sign in to comment.