Permalink
Browse files

Each now accepts vectors

  • Loading branch information...
1 parent b8be46d commit b763abd325a497b04358c2eb9366befc91c25be6 @hadley committed Apr 12, 2009
Showing with 11 additions and 0 deletions.
  1. +1 −0 NEWS
  2. +10 −0 R/helper-each.r
View
@@ -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
View
@@ -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)

0 comments on commit b763abd

Please sign in to comment.