From 157703d21f06f4ec9756ab097853b8cd1906347c Mon Sep 17 00:00:00 2001 From: hadley Date: Fri, 8 Apr 2011 08:29:23 -0500 Subject: [PATCH] Remove row names from colwise --- R/helper-col-wise.r | 22 ++++++---------------- man/colwise.Rd | 15 +++++---------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/R/helper-col-wise.r b/R/helper-col-wise.r index 6f2fd726..a7235642 100644 --- a/R/helper-col-wise.r +++ b/R/helper-col-wise.r @@ -2,17 +2,12 @@ #' Turn a function that operates on a vector into a function that operates #' column-wise on a data.frame. #' -#' By default, the generated function preserves the rownames of the data.frame. -#' To set the rownames differently, you can specify an argument \code{row.names} -#' to the generated function. -#' All other arguments for the generated function will be handed down -#' into the vector function. -#' -#' \code{catcolwise} and \code{numcolwise} provide versions that only operate -#' on discrete and numeric columns respectively. +#' \code{catcolwise} and \code{numcolwise} provide version that only operate +#' on discrete and numeric variables respectively. #' -#' @param .fun function operating on a vector -#' @param .cols either a function that tests columns for inclusion, or a quoted object giving which columns to process +#' @param .fun function +#' @param .cols either a function that tests columns for inclusion, or a +#' quoted object giving which columns to process #' @aliases colwise catcolwise numcolwise #' @export colwise numcolwise catcolwise #' @examples @@ -53,17 +48,12 @@ colwise <- function(.fun, .cols = true) { filter <- function(df) Filter(.cols, df) } - function(df, row.names = NULL, ...) { + function(df, ...) { stopifnot(is.data.frame(df)) - if (is.null(row.names)) row.names <- rownames(df) - filtered <- filter(df) if (ncol(filtered) == 0) return(data.frame()) df <- quickdf(lapply(filtered, .fun, ...)) - if (nrow(df) == length(row.names)) { - rownames(df) <- row.names - } names(df) <- names(filtered) df } diff --git a/man/colwise.Rd b/man/colwise.Rd index 94ee22cf..271c986f 100644 --- a/man/colwise.Rd +++ b/man/colwise.Rd @@ -9,22 +9,17 @@ } \details{ - By default, the generated function preserves the rownames - of the data.frame. To set the rownames differently, you - can specify an argument \code{row.names} to the generated - function. All other arguments for the generated function - will be handed down into the vector function. - - \code{catcolwise} and \code{numcolwise} provide versions - that only operate on discrete and numeric columns + \code{catcolwise} and \code{numcolwise} provide version + that only operate on discrete and numeric variables respectively. } \alias{colwise} \alias{catcolwise} \alias{numcolwise} \arguments{ - \item{.fun}{function operating on a vector} - \item{.cols}{either a function that tests columns for inclusion, or a quoted object giving which columns to process} + \item{.fun}{function} + \item{.cols}{either a function that tests columns for inclusion, or a +quoted object giving which columns to process} } \examples{# Count number of missing values nmissing <- function(x) sum(is.na(x))