You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Wrapped in a function so the same message is issued for the data.frame case at the R level
202
-
voidwarn_matrix_column(/* 1-indexed */inti) {
203
-
warning(_("Some columns are a multi-column type (such as a matrix column), for example column %d. setDT will retain these columns as-is but subsequent operations like grouping and joining may fail. Please consider as.data.table() instead which will create a new column for each embedded column."), i);
204
-
}
201
+
// check no matrix-like columns, #3760. Allow a single list(matrix) is unambiguous and depended on by some revdeps, #3581
202
+
// for performance, only warn on the first such column, #5426
203
+
SEXPcheck_problematic_columns(SEXPx) {
204
+
if (!isNewList(x))
205
+
returnR_NilValue;
206
+
207
+
SEXPxi;
208
+
for (R_len_ti=0; i<LENGTH(x); ++i) {
209
+
xi=VECTOR_ELT(x, i);
205
210
206
-
voiderr_posixl_column(/* 1-indexed */inti) {
207
-
error(_("Column %d has class 'POSIXlt'. Please convert it to POSIXct (using as.POSIXct) and run setDT() again, or use as.data.table() instead. We do not recommend the use of POSIXlt at all because it uses 40 bytes to store one date."), i);
211
+
if (Rf_inherits(xi, "POSIXlt")) {
212
+
error(_("Column %d has class 'POSIXlt'. Please convert it to POSIXct (using as.POSIXct) and run setDT() again, or use as.data.table() instead. We do not recommend the use of POSIXlt at all because it uses 40 bytes to store one date."), i+1);
213
+
}
214
+
215
+
if (length(getAttrib(xi, R_DimSymbol)) >1) {
216
+
warning(_("Some columns are a multi-column type (such as a matrix column), for example column %d. setDT will retain these columns as-is but subsequent operations like grouping and joining may fail. Please consider as.data.table() instead which will create a new column for each embedded column."), i+1);
217
+
break;
218
+
}
219
+
}
220
+
221
+
returnR_NilValue;
208
222
}
209
223
210
-
// input validation for setDT() list input; assume is.list(x) was tested in R
224
+
// input validation for setDT() list input; assume is.list(x) and check_problematic_columns() was tested in R
211
225
SEXPsetdt_nrows(SEXPx)
212
226
{
213
227
intbase_length=0;
214
-
booltest_matrix_cols= true;
215
228
216
229
for (R_len_ti=0; i<LENGTH(x); ++i) {
217
230
SEXPxi=VECTOR_ELT(x, i);
@@ -220,20 +233,12 @@ SEXP setdt_nrows(SEXP x)
220
233
* e.g. in package eplusr which calls setDT on a list when parsing JSON. Operations which
221
234
* fail for NULL columns will give helpful error at that point, #3480 and #3471 */
222
235
if (Rf_isNull(xi)) continue;
223
-
if (Rf_inherits(xi, "POSIXlt")) {
224
-
err_posixl_column(i+1);
225
-
}
226
236
SEXPdim_xi=getAttrib(xi, R_DimSymbol);
227
237
R_len_tlen_xi;
228
238
// NB: LENGTH() produces an undefined large number here on R 3.3.0.
229
239
// There's also a note in NEWS for R 3.1.0 saying length() should always be used by packages,
230
240
// but with some overhead for being a function/not macro...
0 commit comments