cdt {data.table} | R Documentation |
data.table exported C routines
Description
Some of internally used C routines are now exported. This interface should be considered experimental. List of exported C routines and their signatures are provided below in the usage section.
Usage
# SEXP DT_subsetDT(SEXP x, SEXP rows, SEXP cols);
# p_DT_subsetDT = R_GetCCallable("data.table", "DT_subsetDT");
Details
Details how to use those can be found in Writing R Extensions manual Linking to native routines in other packages section.
An example use with Rcpp
:
dt = data.table::as.data.table(iris) Rcpp::cppFunction("SEXP mysub2(SEXP x, SEXP rows, SEXP cols) { return DT_subsetDT(x,rows,cols); }", include="#include <datatableAPI.h>", depends="data.table") mysub2(dt, 1:4, 1:4)
Note
Be aware C routines are likely to have less input validation than their corresponding R interface. For example one should not expect DT[-5L]
will be equal to .Call(DT_subsetDT, DT, -5L, seq_along(DT))
because translation of i=-5L
to seq_len(nrow(DT))[-5L]
might be happening on R level. Moreover checks that i
argument is in range of 1:nrow(DT)
, missingness, etc. might be happening on R level too.
References
https://cran.r-project.org/doc/manuals/r-release/R-exts.html