Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a2fa23f
Enhancing of error message
Divendra2006 Jan 26, 2025
3c1a7c6
Add Suggested changes
Divendra2006 Jan 26, 2025
e75bc73
Revert to initial changes
Divendra2006 Jan 27, 2025
ea98c19
removal of empty lines
Divendra2006 Feb 18, 2025
822964f
Apply changes from maintainer's commit dbcabb0 to avoid repeated strn…
Divendra2006 Feb 19, 2025
594d126
Merge branch 'master' into error-enhance
Divendra2006 Feb 26, 2025
eff26ca
add test case
Divendra2006 Feb 26, 2025
18d0180
changes added
Divendra2006 Feb 26, 2025
94173d1
add test
Divendra2006 Feb 27, 2025
11345b9
add test
Divendra2006 Feb 27, 2025
a26924c
add test
Divendra2006 Feb 27, 2025
7b74601
add test result
Divendra2006 Feb 27, 2025
ec3ea65
test added 1
Divendra2006 Feb 27, 2025
ba8131c
Revert "add test"
Divendra2006 Feb 27, 2025
2493cb5
add test3
Divendra2006 Feb 27, 2025
e66596f
resolved merge conflict
Divendra2006 Feb 27, 2025
89bcb2c
test added for enhancing error message
Divendra2006 Feb 27, 2025
bf867b0
Enhancing of error message
Divendra2006 Jan 26, 2025
dd37750
Revert to initial changes
Divendra2006 Jan 27, 2025
599ff52
Provide a .formula2varlist implementation (#6842)
aitap Feb 26, 2025
fcd1cab
Fix index printing by adding index info to header (#6816)
Mukulyadav2004 Feb 27, 2025
7823be7
xyz
Divendra2006 Feb 28, 2025
cf6140f
Merge branch 'master' into error-enhance
aitap Feb 28, 2025
3f5bed9
modify test
Divendra2006 Feb 28, 2025
c56a711
test case added
Divendra2006 Feb 28, 2025
778f20b
issues resolved
Divendra2006 Feb 28, 2025
53f3e0a
update test case
Divendra2006 Feb 28, 2025
d62dc76
Merge branch 'master' into error-enhance
Divendra2006 Feb 28, 2025
650fe7a
Merge branch 'master' into error-enhance
Divendra2006 Mar 7, 2025
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
5 changes: 5 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21079,3 +21079,8 @@ setindex(DT, b)
# make sure that print(DT) doesn't warn due to the header missing index column types, #6806
# can't use output= here because the print() call is outside withCallingHandlers(...)
test(2307, { capture.output(print(DT, class = TRUE, show.indices = TRUE)); TRUE })

# test for enhancing error message of invalid column #6512
test(2308, {
melt(data.table(A = 1:5, B = 6:10), id.vars = c("A", "-1"))
}, error = "One or more values in 'id.vars' are invalid")
Copy link
Member

Choose a reason for hiding this comment

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

this test case is irrelevant.

please add test cases for the new functionality.

31 changes: 22 additions & 9 deletions src/fmelt.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,30 @@ SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) {
SEXP int_vec = PROTECT(isNewList(int_or_list) ? unlist_(int_or_list) : int_or_list);
SEXP is_duplicated = PROTECT(duplicated(int_vec, FALSE));
int n_unique_cols = 0;
for (int i=0; i<length(int_vec); ++i) {
SEXP invalid_columns = PROTECT(allocVector(INTSXP, length(int_vec)));
int* invalid_col_ptr = INTEGER(invalid_columns);
int invalid_count = 0;
for (int i = 0; i < length(int_vec); ++i) {
int col_number = INTEGER(int_vec)[i];
bool good_number = 0 < col_number && col_number <= ncol;
bool good_number = (col_number > 0 && col_number <= ncol);
if (is_measure) good_number |= (col_number==NA_INTEGER);
if (!good_number) {
if (is_measure) {
error(_("One or more values in 'measure.vars' is invalid."));
} else {
error(_("One or more values in 'id.vars' is invalid."));
}
} else if (!LOGICAL(is_duplicated)[i]) n_unique_cols++;
invalid_col_ptr[invalid_count++] = col_number;
} else if (!LOGICAL(is_duplicated)[i]) {
n_unique_cols++;
}
}
if (invalid_count > 0) {
char buffer[4096] = "", *nexti = buffer;
size_t remaining = sizeof buffer;
for (int i = 0; i < invalid_count; ++i) {
int offset = snprintf(nexti, remaining, "%s[%d]", i > 0 ? ", " : "", invalid_col_ptr[i]);
if (offset < 0 || (size_t)offset >= remaining) break;
nexti += offset;
remaining -= offset;
}
error(_("One or more values in '%s' are invalid; please fix by removing: %s"),
is_measure ? "measure.vars" : "id.vars", buffer);
}
SEXP unique_col_numbers = PROTECT(allocVector(INTSXP, n_unique_cols));
int unique_i = 0;
Expand All @@ -199,7 +212,7 @@ SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) {
}
}
SEXP out = set_diff(unique_col_numbers, ncol);
UNPROTECT(3);
UNPROTECT(4);
return out;
}

Expand Down
Loading