Skip to content
Closed
Show file tree
Hide file tree
Changes from 24 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
3 changes: 3 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -21075,3 +21075,6 @@ 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, {msg <- tryCatch({ .Call("uniq_diff", as.integer(c(1, 2, -1, 4)), 4, FALSE); NULL }, error = function(e) e$message)print(msg)return(grepl("\\[-1\\]", msg))}, TRUE)
46 changes: 35 additions & 11 deletions src/fmelt.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,33 +176,57 @@ bool is_default_measure(SEXP vec) {

// maybe unlist, then unique, then set_diff.
SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) {
// Protect input list/vector, unlisting if necessary
SEXP int_vec = PROTECT(isNewList(int_or_list) ? unlist_(int_or_list) : int_or_list);

// Check for duplicated elements in the input vector
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;
if (is_measure) good_number |= (col_number==NA_INTEGER);
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;
for (int i=0; i<length(is_duplicated); ++i) {

// Populate the unique column numbers into the new vector
for (int i = 0; i < length(is_duplicated); ++i) {
if (!LOGICAL(is_duplicated)[i]) {
INTEGER(unique_col_numbers)[unique_i++] = INTEGER(int_vec)[i];
}
}

// Apply set difference to get final unique column indices
SEXP out = set_diff(unique_col_numbers, ncol);
UNPROTECT(3);
UNPROTECT(4);
return out;
}




SEXP cols_to_int_or_list(SEXP cols, SEXP dtnames, bool is_measure) {
switch(TYPEOF(cols)) {
case STRSXP : return chmatch(cols, dtnames, 0);
Expand Down
Loading