|
1 | 1 | #include "data.table.h" |
2 | 2 | #include <Rdefines.h> |
3 | | - |
4 | 3 | // #include <signal.h> // the debugging machinery + breakpoint aidee |
5 | 4 | // raise(SIGINT); |
6 | 5 |
|
@@ -178,64 +177,46 @@ bool is_default_measure(SEXP vec) { |
178 | 177 | // maybe unlist, then unique, then set_diff. |
179 | 178 | SEXP uniq_diff(SEXP int_or_list, int ncol, bool is_measure) { |
180 | 179 | SEXP int_vec = PROTECT(isNewList(int_or_list) ? unlist_(int_or_list) : int_or_list); |
181 | | - |
182 | 180 | SEXP is_duplicated = PROTECT(duplicated(int_vec, FALSE)); |
183 | | - |
184 | 181 | int n_unique_cols = 0; |
185 | | - |
186 | 182 | SEXP invalid_columns = PROTECT(allocVector(INTSXP, length(int_vec))); |
187 | 183 | int* invalid_col_ptr = INTEGER(invalid_columns); |
188 | 184 | int invalid_count = 0; |
189 | | - |
190 | 185 | for (int i = 0; i < length(int_vec); ++i) { |
191 | 186 | int col_number = INTEGER(int_vec)[i]; |
192 | | - |
193 | 187 | bool good_number = 0 < col_number && col_number <= ncol; |
194 | | - |
195 | 188 | if (is_measure) good_number |= (col_number == NA_INTEGER); |
196 | | - |
197 | 189 | if (!good_number || col_number == 0) { |
198 | 190 | invalid_col_ptr[invalid_count++] = col_number; |
199 | 191 | } else if (!LOGICAL(is_duplicated)[i]) { |
200 | 192 | n_unique_cols++; |
201 | 193 | } |
202 | 194 | } |
203 | | - |
204 | 195 | if (invalid_count > 0) { |
205 | 196 | char buffer[4096] = ""; |
206 | 197 | for (int i = 0; i < invalid_count; ++i) { |
207 | 198 | char temp[32]; |
208 | 199 | snprintf(temp, 32, "[%d]", invalid_col_ptr[i]); |
209 | | - |
210 | 200 | if (i > 0) { |
211 | 201 | strncat(buffer, ", ", sizeof(buffer) - strlen(buffer) - 1); |
212 | 202 | } |
213 | 203 | strncat(buffer, temp, sizeof(buffer) - strlen(buffer) - 1); |
214 | 204 | } |
215 | | - |
216 | | - error(_("One or more values in '%s' are invalid; please fix by removing: %s"), |
| 205 | + error(_("One or more values in '%s' are invalid; please fix by removing: %s"), |
217 | 206 | is_measure ? "measure.vars" : "id.vars", buffer); |
218 | 207 | } |
219 | | - |
220 | 208 | SEXP unique_col_numbers = PROTECT(allocVector(INTSXP, n_unique_cols)); |
221 | 209 | int unique_i = 0; |
222 | | - |
223 | 210 | for (int i = 0; i < length(is_duplicated); ++i) { |
224 | 211 | if (!LOGICAL(is_duplicated)[i]) { |
225 | 212 | INTEGER(unique_col_numbers)[unique_i++] = INTEGER(int_vec)[i]; |
226 | 213 | } |
227 | 214 | } |
228 | | - |
229 | 215 | SEXP out = set_diff(unique_col_numbers, ncol); |
230 | | - |
231 | 216 | UNPROTECT(4); |
232 | | - |
233 | 217 | return out; |
234 | 218 | } |
235 | 219 |
|
236 | | - |
237 | | - |
238 | | - |
239 | 220 | SEXP cols_to_int_or_list(SEXP cols, SEXP dtnames, bool is_measure) { |
240 | 221 | switch(TYPEOF(cols)) { |
241 | 222 | case STRSXP : return chmatch(cols, dtnames, 0); |
|
0 commit comments