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

Add helpful diagnostic error to setDT #3122

Merged
merged 3 commits into from
Dec 6, 2018
Merged

Add helpful diagnostic error to setDT #3122

merged 3 commits into from
Dec 6, 2018

Conversation

MichaelChirico
Copy link
Member

Closes #3121

@codecov
Copy link

codecov bot commented Oct 19, 2018

Codecov Report

Merging #3122 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3122      +/-   ##
==========================================
+ Coverage   92.34%   92.34%   +<.01%     
==========================================
  Files          61       61              
  Lines       11585    11590       +5     
==========================================
+ Hits        10698    10703       +5     
  Misses        887      887
Impacted Files Coverage Δ
R/data.table.R 92.76% <100%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7eefead...bd34f6c. Read the comment docs.

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)) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (any(idx <- n<mn)) {
if (min(n) < mn)
idx <- n < mn

(faster)

Copy link
Member Author

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], '...')
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

max(n) already known
@mattdowle mattdowle added this to the 1.12.0 milestone Dec 6, 2018
@mattdowle mattdowle merged commit 0fc6dde into master Dec 6, 2018
@mattdowle mattdowle deleted the setDT_error branch December 6, 2018 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants