Skip to content
Prev 22936 / 63421 Next

Data table in C

"Tom McCallum" <tom.mccallum at levelelimited.com> writes:
[snip]
One approach is to return a named list and then turn that into a
data.frame like:

ret <- .Call("yourFunc", ...)
attr(ret, "row.names") <- as.integer(indx)
class(ret) <- "data.frame"

In C, you need to create a list (VECSXP) and a character vector
(STRSXP) for the names and then put the names on the list.

PROTECT(ret = allocVector(VECSXP, N));
PROTECT(retnames = allocVector(STRSXP, N));

/* fill list and names */

SET_NAMES(ret, retnames);

+ seth