diff --git a/src/data.table.h b/src/data.table.h index f4d22b95a..70f5a9bb1 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -286,6 +286,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 1ee424314..02959bdcd 100644 --- a/src/init.c +++ b/src/init.c @@ -151,6 +151,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 77c428773..60c508977 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