-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add helpful diagnostic error to setDT #3122
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3122 +/- ##
==========================================
+ Coverage 92.34% 92.34% +<.01%
==========================================
Files 61 61
Lines 11585 11590 +5
==========================================
+ Hits 10698 10703 +5
Misses 887 887
Continue to review full report at Codecov.
|
R/data.table.R
Outdated
@@ -2752,8 +2752,15 @@ setDT <- function(x, keep.rownames=FALSE, key=NULL, check.names=FALSE) { | |||
} | |||
n = vapply(x, length, 0L) | |||
mn = max(n) | |||
if (any(n<mn)) | |||
stop("All elements in argument 'x' to 'setDT' must be of same length") | |||
if (any(idx <- n<mn)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (any(idx <- n<mn)) { | |
if (min(n) < mn) | |
idx <- n < mn |
(faster)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HughParsonage nice. I guess n_rng = range(n)
even faster then...
R/utils.R
Outdated
# (common aggregation method for error messages) | ||
brackify = function(x) { | ||
# arbitrary cutoff | ||
if (length(x) > 10L) x = c(x[1:10], '...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very nice you handle that already but could also be tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jangorecki see #3117
max(n) already known
ab0729d
to
c502595
Compare
Closes #3121