Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequential Summarise fixes issue #44 #89

Merged
merged 2 commits into from Oct 5, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions R/helper-summarise.r
Expand Up @@ -18,8 +18,8 @@
#' duration = max(year) - min(year),
#' nteams = length(unique(team)))
summarise <- function(.data, ...) {
cols <- eval(substitute(list(...)), .data, parent.frame())
cols <- as.list(substitute(list(...))[-1])

# ... not a named list, figure out names by deparsing call
if(is.null(names(cols))) {
missing_names <- rep(TRUE, length(cols))
Expand All @@ -30,7 +30,10 @@ summarise <- function(.data, ...) {
names <- unname(unlist(lapply(match.call(expand = FALSE)$`...`, deparse)))
names(cols)[missing_names] <- names[missing_names]
}

quickdf(cols)
.data <- as.list(.data)
for (col in names(cols)) {
.data[[col]] <- eval(cols[[col]], .data, parent.frame())
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, could you take an approach more similar to mutate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revised the patch to just convert the input data frame to a list to remove the ugly environment copying I was doing. This also improved performance, however the conversion still makes this version slower than the non iterative version. This version is much closer to the mutate implementation.

quickdf(.data[names(cols)])
}
summarize <- summarise