Skip to content

Commit

Permalink
uniqueN handle NULL, closes #1429
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki committed Nov 10, 2015
1 parent caab62a commit 51141fa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/duplicated.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ anyDuplicated.data.table <- function(x, incomparables=FALSE, fromLast=FALSE, by=
# of groups in a vector or data.table. Here by data.table,
# we really mean `.SD` - used in a grouping operation
uniqueN <- function(x, by = if (is.data.table(x)) key(x) else NULL) {
if (!is.atomic(x) && !is.data.frame(x))
if (is.null(x) || (!is.atomic(x) && !is.data.frame(x)))
return(length(unique(x)))
if (is.atomic(x)) x = as_list(x)
if (is.null(by)) by = seq_along(x)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@

16. `rleid()` does not affect attributes of input vector, [#1419](https://github.com/Rdatatable/data.table/issues/1419). Thanks @JanGorecki.

17. `uniqueN()` now handle NULL properly, [#1429](https://github.com/Rdatatable/data.table/issues/1429). Thanks @JanGorecki.

#### NOTES

1. Updated error message on invalid joins to reflect the new `on=` syntax, [#1368](https://github.com/Rdatatable/data.table/issues/1368). Thanks @MichaelChirico.
Expand Down
2 changes: 2 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -7214,6 +7214,8 @@ test(1581.12, any(grepl("^GForce optimized j", opt2)), TRUE)

options(datatable.optimize=optim)

# handle NULL value correctly #1429
test(1582, uniqueN(NULL), 0L)

##########################

Expand Down

0 comments on commit 51141fa

Please sign in to comment.