Skip to content

Commit

Permalink
Merge pull request #163 from richierocks/master
Browse files Browse the repository at this point in the history
Fixes for Issue 130
  • Loading branch information
hadley committed Jan 2, 2014
2 parents 10978f4 + 200321b commit c06df49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ BUG FIXES

* `*aply` now accepts 0-dimension arrays as inputs. (#88)

* `count` now works correctly for factor and Date inputs. (Fixes #130)

* `*dply` now deals better with matrix results, converting them to data frames, rather than vectors. (Fixes #12)

* `d*ply` will now preserve factor levels input if `drop = FALSE` (#81)
Expand Down Expand Up @@ -423,4 +425,4 @@ Version 0.1.1 (2008-10-08)

* argument names now start with . (instead of ending with it) - this should prevent name clashes with arguments of the called function
* return informative error if .fun is not a function
* use full names in all internal calls to avoid argument name clashes
* use full names in all internal calls to avoid argument name clashes
2 changes: 1 addition & 1 deletion R/count.r
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' count(count(baseball[1:100,], c("id", "year")), "id", "freq")
#' count(count(baseball, c("id", "year")), "freq")
count <- function(df, vars = NULL, wt_var = NULL) {
if (is.vector(df)) {
if (is.atomic(df)) {
df <- data.frame(x = df)
}

Expand Down
14 changes: 14 additions & 0 deletions inst/tests/test-count.r
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ test_that("weighted count matches xtab", {
expect_that(ct2, equals(xt2))

})

test_that("count works with factors and dates", {
genders <- c("Female", "Male")
n <- c(5, 10)
gender_data <- factor(rep.int(genders, n))

expect_equal(count(gender_data), data.frame(x = genders, freq = n))

this_week <- seq(Sys.Date(), Sys.Date() + 6, "1 day")
n2 <- 1:7
day_data <- rep(this_week, n2)

expect_equal(count(day_data), data.frame(x = this_week, freq = n2))
})

0 comments on commit c06df49

Please sign in to comment.