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

uniqueN handle NULL, closes #1429 #1430

Merged
merged 1 commit into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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