diff --git a/src/data.table.h b/src/data.table.h index 1fe8bd68f..129a5bf21 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -287,6 +287,7 @@ SEXP notchin(SEXP x, SEXP table); // mergelist.c SEXP cbindlist(SEXP x, SEXP copyArg); +SEXP copyCols(SEXP x, SEXP cols); // functions called from R level .Call/.External and registered in init.c // these now live here to pass -Wstrict-prototypes, #5477 diff --git a/src/init.c b/src/init.c index 8dd8277f7..e23467771 100644 --- a/src/init.c +++ b/src/init.c @@ -152,6 +152,7 @@ R_CallMethodDef callMethods[] = { {"Cnotchin", (DL_FUNC)¬chin, -1}, {"Ccbindlist", (DL_FUNC) &cbindlist, -1}, {"CperhapsDataTableR", (DL_FUNC) &perhapsDataTableR, -1}, +{"CcopyCols", (DL_FUNC) ©Cols, -1}, {"Cwarn_matrix_column_r", (DL_FUNC)&warn_matrix_column_r, -1}, {NULL, NULL, 0} }; diff --git a/src/mergelist.c b/src/mergelist.c index 533424bf6..6d052cbac 100644 --- a/src/mergelist.c +++ b/src/mergelist.c @@ -1,5 +1,22 @@ #include "data.table.h" +// set(x, NULL, cols, copy(unclass(x)[cols])) ## but keeps the index +SEXP copyCols(SEXP x, SEXP cols) { + // used in R/mergelist.R + if (!isDataTable(x)) + error("'x' must be a data.table"); // # nocov + if (!isInteger(cols)) + error("'cols' must be integer"); // # nocov + int nx = length(x), ncols = LENGTH(cols), *colsp = INTEGER(cols); + if (!nx || !ncols) + return R_NilValue; + for (int i=0; i